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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:57:46+00:00 2026-05-22T01:57:46+00:00

I want to display a message to the user depending upon a prompt I

  • 0

I want to display a message to the user depending upon a prompt I receive from another part of the program. There can be a number of prompts & they are stored in an enum.

These are my prompts:

Defs.java

public enum Prompt
{
    PromptA,
    PromptB,
    PromptC,
}

I have the externalized strings stored in resources on these lines:

res/values/strings.xml

<string name="PromptA">Error in execution</string>
<string name="PromptB">Process completed successfully</string>
<string name="PromptC">Please try again</string>

Now in my main Activity screen a method is called by some other part:

public void showPrompt(Prompt prompt) {
    String message = getString(R.string.<**what-do-I-put-here?**>);
    //show a dialog box with message
}

I know this can be done with a huge if-else block (there are tons of prompts in the actual application) or a switch statement.
It will be really ugly.

Is there a better way to do this?

  • 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-22T01:57:47+00:00Added an answer on May 22, 2026 at 1:57 am

    See Resources.getIdentifier: http://developer.android.com/reference/android/content/res/Resources.html#getIdentifier%28java.lang.String,%20java.lang.String,%20java.lang.String%29 . You can try something like this:

    public void showPrompt(Prompt prompt, String label) {
        String message = (String) getResources().getText(getResources().getIdentifier(label, "string", null));
        //show a dialog box with message
    }
    

    Try that out and see what that does for you.

    EDIT: meh. Try this instead.

    public void showPrompt(Prompt prompt, String label) {
        String message = (String) getResources().getText(getResources().getIdentifier(label, "string", "<application package class>"));
        //show a dialog box with message
    }
    

    Turns out you have to specify the your package identifier (so if your AndroidManifest.xml has com.blah.blah.blah as the Package put that in the third parameter.

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

Sidebar

Related Questions

I want to store a user message in a bash program, and then display
Hai Friends, I want to display a toast message to the user, when there
I want to make an application that would display a message when a user
Rails 2.3.3 Database and Model Schema User (id,name,email) posts (id,subject,message,user_id) How can I display
I want to display to the user a message that says please enable JavaScript
is there any way to display a message when a user loads library(myCustomLibrary) ?
I want to display a alert message when a user clicks on button. I
I want to display a message to the user saying, you're logged out re-login
I want to display message box contain label and textbox and ok button and
I want to display error message or alert message after checking the condition. here

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.