Reputation: 207902
I have an activity with three listviews, each having three different cursors, but all have the same ContextMenu show/resolve code and when the selection event fires, I want to get the ListView to refresh it.
I can't use menuInfo.targetView
, as that holds the LinearLayout for the ListView row, and not the ListView.
in this method
public boolean onContextItemSelected(MenuItem item)
How is possible?
Upvotes: 0
Views: 462
Reputation: 68444
EDIT: I was wrong.Several ListView will work together on the same screen. Might be challenging due to real estate but will work.
Upvotes: -1
Reputation: 57166
You are attaching Tag
s/Holders to row View
s in Adapter
s, right?
Have a Tag class per Adapter.
Now,
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo();
Class<?> tagClass = info.targetView.getTag().getClass();
if(tagClass == FirstTag.class){
// the first list
} else if(tagClass == SecondTag.class){
// the second one
} else {
throw new IllegalArgumentException('I've screwed up this hack.');
}
//...
}
Upvotes: 1
Reputation: 10031
Use MenuInfo, passed as the third argument of onCreateContextMenu()
. You could add a reference to your ListView, for example. You can query it by item.getMenuInfo()
.
Edit: sorry, there isn't a way to set MenuInfo.
Try creating the context menu items with different groupIDs for each listView, then you can switch based onMenuItem.getGroupId()
.
Upvotes: 1