Home Forum
Welcome, Guest
Username Password: Remember me

Context menu select handling
(1 viewing) (1) Guest
Discussion related to creating Android software
  • Page:
  • 1

TOPIC: Context menu select handling

Context menu select handling 2 years, 9 months ago #170

Given the common situation of responding to a context menu launched after a long press on a list view its probable that you want to know which item was long pressed.

I found this obscure and took a little digging to find, when in the onContextItemSelected its easy to work out with item in the context menu was selected, what I could not find was which item was currently selected in the list that was long pressed to get the context menu.

The answer is:

 
AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
 

This object contains information about the position of the selected item in the list view.

Another bit of advice is that when extending the BaseAdapter class is to return a real data object form the getItem() member rather than the int as a position (as in the example I followed when I did the first one) The reason is that other wise you will need to keep a separate copy of the items in the list to use when the user selects an item to get the details.
  • marvin
  • OFFLINE
  • Professor
  • Posts: 18
  • Karma: 0
  • Page:
  • 1
Time to create page: 0.21 seconds
Copyright © 2012 Android Academy. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.
 
Glossary
We have 26 guests online