I’m switching some code over to the FragmentTabsPager design model, which does a nice job providing both tabbed navigation and page swiping (see FragmentTabsPager and ABS version of FragmentTabsPager).
But I can’t figure out how to produce a ContextMenu when a list item is selected. Previously I would do it simply by calling:
ListView listView = (ListView) findViewById(R.id.listViewid);
registerForContextMenu(listView);
And then having definitions for onCreateContextMenu() to dynamically generate the menu items, and onContextItemSelected() to execute the appropriate action based on the item selected.
The problem I’m having now is that in the FragmentTabsPager model, the listview is dynamically generated — not in an XML file — so there isn’t an obvious place to get the listView for the registerForContextMenu call.
Any idea how to do this? Thanks.
I figured out how to do make context menus work with the FragmentTabsPager.
First, using the FragmentTabsPager mentioned above, integrate the mTabsAdapter.addTab() calls from FragmentTabsPager.java into your Activities that have a Sherlock Actionbar, and for which you want to implement swiping.
Then, modify AccountListActivity.java from the same repository by adding onCreateContextMenu() and onContextItemSelected() to the AccountListFragment.
The ContextMenu callbacks will be invoked on your list items after you call
from the onActivityCreated() function. Getting the right argument for the registration call is the bit I was missing. Good luck!