开发者

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 onContextItemSele开发者_如何学运维cted(MenuItem item) 

How is possible?


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.');
        }
        //...
    }


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().


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


EDIT: I was wrong.Several ListView will work together on the same screen. Might be challenging due to real estate but will work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜