我想根据从程序的其他部分收到的提示向用户显示消息.可以有许多提示,它们存储在枚举中.
这些是我的提示:
Defs.java
public enum Prompt
{
PromptA,
PromptB,
PromptC,
}
Run Code Online (Sandbox Code Playgroud)
我将外化字符串存储在这些行的资源中:
RES /值/ strings.xml中
<string name="PromptA">Error in execution</string>
<string name="PromptB">Process completed successfully</string>
<string name="PromptC">Please try again</string>
Run Code Online (Sandbox Code Playgroud)
现在在我的主Activity屏幕中,一个方法被其他部分调用:
public void showPrompt(Prompt prompt) {
String message = getString(R.string.<**what-do-I-put-here?**>);
//show a dialog box with message
}
Run Code Online (Sandbox Code Playgroud)
我知道这可以通过一个巨大的if-else块(实际应用程序中有大量提示)或switch语句来完成.这真的很难看.
有一个更好的方法吗?