代码中的参考字符串资源 [英] Reference string resource from code
本文介绍了代码中的参考字符串资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在strings.xml中声明了以下字符串:
I have the following string declared in strings.xml:
<string name="last_msg">Your last click was on</string>
现在,当有人单击按钮时,我希望文本视图显示此字符串,并带有空格,然后是时间戳的变量值.
Now when someone clicks a button, I want a textview to show this string, with a space, then a variable value that is a timestamp.
不幸的是,使用@ string/last_msg无法正常工作,我不确定如何正确执行此操作,因此不会对内容进行硬编码.
Unfortunately, using @string/last_msg isn't working, and I'm not sure how to do this properly so I'm not hardcoding in content.
这是我的onClick函数代码:
Here's my code for the onClick function:
public void showMsgNow(View view) {
TextView lastMsg = (TextView)findViewById(R.id.textView2);
long currentTimeStamp = System.currentTimeMillis();
lastMsg.setText(@string/last_msg + " " + currentTimeStamp);
}
我是新手,任何帮助都很棒!
I'm a newbie, any help would be great !
推荐答案
我在Google上找到了答案:
I found the answer on Google:
getString(R.string.last_msg)
这篇关于代码中的参考字符串资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文