2013-10-01 35 views
0

在做了很多教程之后,我正在玩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时,它将字符串变成数字。

有没有办法避免这种情况?

+1

R.string.welcome2是整数资源字符串ID。你应该得到字符串本身。 getReources()。的getString(R.string.welcome2) – Leonidos

回答

0

要追加,我认为不会有,但肯定的,你可以连接这样

String outStr = getString(R.string.first) + 
    " " + getString(R.string.second); 

做参考Link to refrence

0
String welcomestr = Context.getResources().getString(R.string.welcome2) 
    gamehistory = (TextView)findViewById(R.id.textView2); 
    gamehistory.setText(welcomestr); 
0

使用Context.getResources().getString(id)了点。

getReources().getString(R.string.welcome2); // Since you're calling this in your activity itself. 

因为R.string.welcome2是您的字符串资源的自动生成的整数值。

0

尝试添加回车。

gamehistory.append("\r\n" + R.string.welcome2); 

或者将这些行添加到XML的TextView的一部分:

android:maxLines="2" 
android:minLines="1"