views:

55

answers:

3

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?

+1  A: 

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

molnarm
How do I pass that ListView forward to `onContextItemSelected` method?
Pentium10
A: 

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

Alex Volovoy
This answer doesn't relates to the problem. Don't make up things that the OP doesn't told, ask before. The ListViews are on separate Tabs, UI is consistent, and again it's not the problem I am facing.
Pentium10
Also don't forget that Android can be use on set-top boxes like TVs, where having multiple scrollable areas is different.
Pentium10
If your ListViews are on separate tabs, then you can determine which tab you're on (TabHost.getCurrentTab()) so you'll now which ListView to refresh.
molnarm
I was definitely wrong. Multiplay list/grid view will be fine as long as they not wrapped up in the ScrollView.
Alex Volovoy
+1  A: 

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.');
        }
        //...
    }
alex
This method is good and usable, although getting the ListView would be the best. I hope someone will answer it.
Pentium10