3

When editing my strings.xml under res/values I can see them appearing in gen/my_package/R.java but they are static final int's, why is this?

-Why are they static final, presumably this means I couldn't update them, i.e. if I assign a string to a text box, can that string be updated from my code at some point to update the contents of the text box?

-Also why are these integers, specifically they appear to be hex values. If this is the preferable way of declaring these values, why don't we just declare them as hex values in the first place?

1 Answer 1

8

The int it generates is used by android to retrieve your String. You must have a reference to Context (such as an Activity) in order to get your resources. For example in your activity you could say.

this.getString(R.string.myString);

the getString in Activity is a shortcut to

context.getResources().getString(R.string.myString);

Hope this helps!

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

3 Comments

I see, so its more of a pointer than something I need to actually worry about maintaining?
yep whenever you build your project android will generate an R file that has these static identifiers you can use to get resources from the resource manager like in my example above.
You can have multiple strings.xml each for a different language. Android will automatically choose the right one depending on the users configuration. You don't have to provide multiple .java source for each language you are targeting.

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.