在做了很多教程之后,我正在玩Android。Strings.xml和附加
我有我想要打印,我已经写在strings.xml档案文本的各种线路一个TextView:
<string name="welcome">Welcome! What is your name?</string>
<string name="welcome2">Welcome!</string>
在我的主,我有:
gamehistory = (TextView)findViewById(R.id.textView2);
gamehistory.setText(R.string.welcome);
这工作正常,并显示文字。我想将文本框用作“日志”,以便稍后在我的代码中打印下一行的welcome2。
gamehistory.append("\n" + R.string.welcome2);
不幸的是,当我使用append时,它将字符串变成数字。
有没有办法避免这种情况?
R.string.welcome2是整数资源字符串ID。你应该得到字符串本身。 getReources()。的getString(R.string.welcome2) – Leonidos