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?
prompt.ordinal()? Usingordinalis generally not recommended, as it may be fragile in case you reorder or add an item, but there are many more fragile things when using XML.