Hi all,
I'm stumped.
I have a table with data rows that are dynamically created.
I am trying to map a context menu to each table row that shows "Delete
item", and on click, lets me delete the item.
Simple, right?
The problem is that my onContextItemSelected(MenuItem item) handler
always has a null item.getMoreInfo(). Which is unfortunate, because
that is the only way I can find to get the index of the TableRow
selected.
Does anyone know how to ensure that the MenuItem actually has relevant
information in it?
Am I trying to do something that TableRows were not meant to be doing,
and I should migrate back to a ListLayout (ugh..)?
Or, should I think about an anonymous function handler for each
TableRow on creation (also ugh, if it even works..)?
To provide more details:
1.) Table creation:
while (...)
{
// Build table row
TableRow tr = new TableRow(this);
.. add stuff to tr ..
tr.setOnCreateContextMenuListener(this);
.. add tr to the
TableLayout ..
}
2.) Handling overrides
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfo;
menu.add(0, DELETE_ID, 0, R.string.menu_delete);
}
public boolean onContextItemSelected(MenuItem item) {
super.onContextItemSelected(item);
switch (item.getItemId()) {
case DELETE_ID:
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo();
Log.v(TAG, "ContextMenuInfo info=" + info); // info is ALWAYS
NULL!
.. delete the row, refresh the screen, etc..
return true;
}
return false;
}
Thanks for your help!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---