android - MenuItem#getTag() -


on subclasses of view there gettag() method, returns android:tag attribute's value .xml. same menuitem... okay cast view? because item elements allow tag attribute in .xml...

update: goal setting tag in .xml, i.e. "notranslate", , querying @ runtime (we localize hand @ runtime, don't ask...)

menuitem interface. class can implement interface , not always safe cast menuitem view. can use "instanceof" operator test see if object implements menuitem interface indeed view or not.

i understand want define flag in xml definition of menu , @ run time interrogate flag make programmatic decision.

the menu resource documentation records attributes can set in xml. can consider using (abusing) 1 of settings such "android:alphabeticshortcut" encode flag , use menuitem::getalphabeticshortcut() method value. not require casting - uses existing fields in menuitem xml construct/class own purposes.

perhaps less hacky way keep simple table in separate assets file lists menu item identifiers , special behavior associated identifier such translate or not translate.

alternatively create simple class has table configuration information hard coded using logical "@[+][package:]id/resource_name" resource identifier keys table. while doesn't keep in 1 place (in xml) in manner not encoding information in unused attributes, or relying on ids not changing. "table" implemented static method embedded switch statement allowing code such "if (translationtable.shouldtranslate(menuitem.getitemid())) { translation }"


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -