开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜