senzacionale
senzacionale

Reputation: 20926

read message value from string.xml file in android

i have string like @string/screen_enable_auto_mode. I know that i can use:

String mess = getResources().getString(R.string.screen_enable_auto_mode);

and i will get a message.

But i have whole string as @string/screen_enable_auto_mode. How can i parse it to

String mess = getResources().getString(R.string.screen_enable_auto_mode);

that i will get a message from xml?

Upvotes: 1

Views: 1226

Answers (1)

tom
tom

Reputation: 19163

You can use Resources.getIdentifier for this.

int resId = getResources().getIdentifier(
    "screen_enable_auto_mode", "string", "com.package.app");
String mess = getResources().getString(resId);

Replace "com.package.app" with the actual package of your app, of course.

Upvotes: 3

Related Questions