开发者

Android: strings aren't strings, in strings.xml?

开发者 https://www.devze.com 2023-02-03 03:03 出处:网络
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?

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?


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消