code_junkie

How do you implement context menu in a ListActivity on Android?

Nov 13th, 2011
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. registerForContextMenu(getListView());
  2.  
  3. AdapterView.AdapterContextMenuInfo info;
  4. try {
  5. info = (AdapterView.AdapterContextMenuInfo) menuInfo;
  6. } catch (ClassCastException e) {
  7. Log.e(TAG, "bad menuInfo", e);
  8. return;
  9. }
  10. long id = getListAdapter().getItemId(info.position);
  11.  
  12. menu.add(0, MENU_ITEM_ID, 0, R.string.menu_string);
  13.  
  14. try {
  15. info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
  16. } catch (ClassCastException e) {
  17. Log.e(TAG, "bad menuInfo", e);
  18. return false;
  19. }
  20. long id = getListAdapter().getItemId(info.position);
Add Comment
Please, Sign In to add comment