Identifying the view selected in a ContextMenu (Android)
Posted
by Casebash
on Stack Overflow
See other posts from Stack Overflow
or by Casebash
Published on 2010-05-28T02:18:30Z
Indexed on
2010/05/28
2:21 UTC
Read the original article
Hit count: 212
android
In Android, onContextItemSelected
has a single MenuItem
argument and so it isn't clear how to identify the view selected. MenuItem.getMenuInfo provides access to Contextmenu.ContextMenuInfo, but while both known subclasses provide access to the target view, there does not appear to be an accessor on the interface.
One alternative is to save the View
provided in onCreateContextMenu
in a private class variable which relies on onCreateContextMenu
not being called again in the activity before onContextItemSelected
. Another is to use the id of the View
for the itemId
argument of ContextMenu.add. If we do this, we would then need to identify the option selected from the context menu by using its (possibly internationalised) title.
What is the best method for identifying the View
selected in onContextSelected
?
© Stack Overflow or respective owner