Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6984835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:36:04+00:00 2026-05-27T18:36:04+00:00

On subclasses of View there is a getTag() method, which returns the android:tag attribute’s

  • 0

On subclasses of View there is a getTag() method, which returns the android:tag attribute’s value from .xml.
I would like the same for a MenuItem… is it okay to just cast it to a View?
Because item elements also allow a tag attribute in .xml…

Update: My goal with this is setting a tag in .xml, i.e. "notranslate", and querying it at runtime (we localize by hand at runtime, don’t ask…)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:36:05+00:00Added an answer on May 27, 2026 at 6:36 pm

    MenuItem is an interface. Any class can implement this interface and so it will not always be safe to cast the MenuItem to a View. You can use the “instanceOf” operator to test to see if the object that implements the MenuItem interface is indeed a View or not.

    I understand that you want to define a flag in the XML definition of the menu and then at run time interrogate that flag to make a programmatic decision.

    The Menu Resource Documentation records what attributes can be set in the XML. You can consider using (abusing) one of those settings such as the “android:alphabeticShortcut” to encode the flag and use the MenuItem::getAlphabeticShortcut() method to get the value. This does not require casting – it just uses the existing fields in the MenuItem XML construct/class for your own purposes.

    Perhaps a less hacky way to do this is to keep a simple table in a separate assets file that lists the menu item identifiers and the special behavior associated with that identifier such as to translate or not to translate.

    Alternatively create a simple class that has a table with this configuration information hard coded using the logical “@[+][package:]id/resource_name” resource identifier as the keys to the table. While this doesn’t keep it all in one place (in the XML) it does it in a manner that is not encoding information in unused attributes, or relying on the ids not changing. The “table” could be implemented as a static method with an embedded switch statement allowing code such as “if (TranslationTable.shouldTranslate(menuItem.getItemId())) { do translation }”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Summary From a conceptual point of view, should one be working with UIViewController subclasses
I have an NSControl subclass (which is configured as a layer-hosting view, although I
I have written a subclass of UIViewController which creates a view programmatically, instead of
I have a basic class that derived subclasses inherit from, it carries the basic
Is there a simple way for subclasses of UITableViewCell to show the 'Copy' UIMenuController
I am building a class which subclasses dict , and overrides __setitem__ . I
imagine i have a main view, in which i have a call to the
I am using Qt's QGraphicsView — and QGraphicsItem — subclasses. Is there a way
I have a superclass of type Question which has multiple subclasses (e.g. MultipleChoiceQuestion and
I want to display a selection list of MyModel subclasses in a view. It's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.