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 7521879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:21:27+00:00 2026-05-30T02:21:27+00:00

The suggested way of implementing menus in Android is to use XML to define

  • 0

The suggested way of implementing menus in Android is to use XML to define a menu, which works for static menus. I’m currently trying to create a dynamic sub-menu, though, and I’d like to associate unique item ids with each of the items in a submenu so that I can store metadata with them.

There’s an answer here that suggests using an autoincrementing id, but I also have existing item ids being used for other parts of the menu that look like this (in R.java)

public static final int item2=0x7f070002;

I’m sure I can start at id = 1 and then increment, but if the id generation scheme ever changes for R.java, I’m worried I’ll start seeing collisions. Is there a better way of generating these ids? Or do I just need to keep track of the max id, then start incrementing from there?

  • 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-30T02:21:28+00:00Added an answer on May 30, 2026 at 2:21 am

    The “correct” solution would be to traverse the objects that describe the menus to find all of the ids that are in use, then use a different one.

    But, if you are prepared to live with a small chance of a problem, you could simply generate your dynamic menu ids using a random number generator. Assuming you have 32 bit ids, the probablility of a single collision menu item colliding is N / 2^32 where N is the number of existing menu ids. If we assume a reasonable value for N, that’s a pretty small number …

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

Sidebar

Related Questions

Short Version: Is there a/what is the suggested way to return error details to
Can you suggest a best way to define money type in F#?
I am used to thinking about time estimates in the way suggested by Joel
Are there any suggested practices for implementing long-running operations in Tomcat? e.g. is it
Is there any way to implement a multi-threading execution in Javascript. I am implementing
I am implementing an authentication system into an existing database system. Currently, the database
I am implementing jQuery UI Autocomplete and am wondering if there is any way
I am implementing the complex algorithm which part is sorting array of ordered sequences
I am currently trying to implement a grid view in the iPhone SDK, whereby
I am trying to create table using TTTableViewController . I want to display an

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.