我在 strings.xml 中声明了以下字符串:
<string name="last_msg">Your last click was on</string>
现在当有人点击一个按钮时,我想要一个 TextView 来显示这个字符串,一个空格,然后是一个变量值,它是一个时间戳。
不幸的是,使用@string/last_msg 不起作用,我不确定如何正确执行此操作,所以我没有对内容进行硬编码。
这是我的 onClick 函数代码:
public void showMsgNow(View view) {
TextView lastMsg = (TextView)findViewById(R.id.textView2);
long currentTimeStamp = System.currentTimeMillis();
lastMsg.setText(@string/last_msg + " " + currentTimeStamp);
}
我是新手,任何帮助都会很棒!
最佳答案
我在 Google 上找到了答案:
getString(R.string.last_msg)
关于android - 从代码中引用字符串资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10698945/