milkamar milkamar - 1 month ago 7
Android Question

Get unique identifier for ContextMenu in Android?

Have defined xml for my context menu

mymenu.xml
.

Want every menu inflated from this xml to provide same unique identifier - so I know it was inflated from
mymenu.xml
file.

Tried
hashCode()
or
toString()
on
Menu
but found out,
that new
ContextMenu
instance is created on every
onCreateContextMenu
call and so these values differ.

<menu>
tag cannot have some unique attribute set also.

So, my question:

Is it possible to get
String
containing name of xml from which was menu inflated,
( in my case
"mymenu"
),
or some other per-xml unique value, which would not be defined programatically by me?

(for example summing
id
's from all its
MenuItem
s)

Thanks for any response :)

Answer

Finally found out, that R.menu.mymenu does that. It returns unique int per xml.

Comments