Search code examples
androidandroid-imageviewandroid-tablelayoutandroid-contextmenu

How do you pass an ImageView's ID to onContextItemSelected?


I am registering a floating context menu to an ImageView in a TableLayout and opening the menu with setOnClickListener. I am wondering how to get the ImageView's id in onContextItemSelected. AdapterContextMenuInfo only returns null because, I'm assuming, ImageView doesn't use an Adapter. xnagyg's answer in this question, why item.getMenuInfo() is null?, in essence does what I want but what is the proper way of accessing the ImageView's id?


Solution

  • You can do the suggestion in the link you posted, or you can build a data structure to indicate which views = what id. You could use a hashmap of [view's id,position] (can't use carrots) and then update this every time a view is modified.