Pentium10
Pentium10

Reputation: 207902

How to get on which ListView has been a ContextItem selected?

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

Answers (4)

user479288
user479288

Reputation:

Try menuInfo.targetView.getParent() - this is the ListView itself.

Upvotes: 0

Alex Volovoy
Alex Volovoy

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

yanchenko
yanchenko

Reputation: 57166

You are attaching Tags/Holders to row Views in Adapters, 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

molnarm
molnarm

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

Related Questions