3

I have xml folder in my res folder with file structured like this:

    <questions>
        <question
            number="1"
            text="my string" 
            numberTwo="1" />
         ...
    </questions/

So is that possible not to hardcode strings here and use @string/... resources because I really need localization here?

2 Answers 2

2

You can have

text="mystring" in your xml file

and <string name"mystring">lalala</string> in your strings.xml (possibly localized in other files such as in a folder values-de.xml)

Then in your code you can do:

int stringId = getResources().getIdentifier("mystring", "string");
String string = getString(stringId); // that will be "lalala"

The other way is to have your xml file entirely localized in the folder xml-de but this incurs some text duplication.

Sign up to request clarification or add additional context in comments.

Comments

0

In string.xml ->lalala in your strings.xml ->folder values-de.xml Then in your code you can do in Activity:

String AppName=getResources().getString(R.string.app_name);

And in Fragmetn

String AppName=getActivity().getResources().getString(R.string.app_name);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.