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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:02:13+00:00 2026-06-16T11:02:13+00:00

I am writing my first Android app. It will have hundreds of menu links

  • 0

I am writing my first Android app. It will have hundreds of menu links that will change with each version released. I am looking for a way to process the onclicks based on the Resource ID.

Menus are defined in XML like so:

<item android:id="@+id/Spring_2013" android:title="Spring 2013" android:showAsAction="ifRoom|withText" />

The onclicks will load a URL stored in strings.xml:

<string name="Summer_2013">file:///android_asset/catalog/current/genadmissionreq.html</string>

So, seems like all I need is a simple, single onclick method that loads whatever string is needed based on the selected Resource ID. The MenuItem ID is ALWAYS equal to the URL string ID in my code. So, without using hundreds of if() or switch/case statments, cant I just say:

String url = getString("R.string." + menuItem.getItemId());

Obviously that assignment wont work for a number of reasons. But you get the idea right? So, how CAN I make this work?

Im sorry for the newb question. I know it should be simple but I’ve been reading for days and cannot find any way to do this without an if() statement for EVERY menu item. That method would make the weekly updates a nightmare!

  • 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-06-16T11:02:14+00:00Added an answer on June 16, 2026 at 11:02 am

    Try using getIdentifier()

    String title = menuItem.getTitle().toString().replace(' ', '_');
    id = getResources().getIdentifier(title, "string", getPackageName());
    String string = getString(id);
    

    The first line fetches Spring 2013 and converts it to Spring_2013.
    The second line builds "R.string." with whatever the title is, in this case "R.string.Spring_2013".
    The third line simply fetches the String resource.

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

Sidebar

Related Questions

I am currently writing my first Android app and have based most of my
To begin with, this is the first Android app I'm writing, and I have
I am writing my first Android app. I have three Activities: BaseballCardList, BaseballCardDetails, and
I have an android app I am writing that uses SQLite. I want the
I am writing an android app that when I run it first time it
Im new to android. I have been writing my first app, I testing it
I'm writing my first android app (I'm a noob at android, but decent at
Hurro! I'm trying my hand at writing my first Android app, and I've hit
I'm writing my first Rails app and I'm confused by a method call that
I'm writing my first client/server android app, and need an advice regarding server architecture.

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.