2015年8月16日 星期日

[Android] Reference one string from another string in strings.xml? (轉貼)


reference:
http://stackoverflow.com/questions/4746058/reference-one-string-from-another-string-in-strings-xml?rq=1


I think you can't. But you can "format" a string as you like:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="button_text">Add item</string>
    <string name="message_text">You don't have any items yet! Add one by pressing the %1$s button.</string>
</resources>
In the code:
Resources res = getResources();
String text = String.format(res.getString(R.string.message_text),
                            res.getString(R.string.button_text));

沒有留言:

張貼留言