在做了很多教程之後,我正在玩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