2013-04-11 37 views
0

我有一个textView,我想同时显示两个不同的变量,每个变量都在一行上。 这里是我迄今为止Android显示多个变量textView

TextView.setText("You answered :" + " " + correct + "correct" + '\n'); 
TextView.setText("You answered: " + " " + wrong + "incorrect"); 

这只是显示的最后一行,而不是代码TextView的两条线。任何人都可以告诉我如何在两个不同的行上同时在相同的textView中同时显示这两个文件?非常感激。

回答

1
String text = "You answered :" + " " + correct + "correct\n" +"You answered: " + " " + wrong + "incorrect"; 
TextView.setText(text); 
1

使用此代码剪断:

TextView.setText("You answered :" + " " + correct + "correct\n" +"You answered: " + " " + wrong + "incorrect"); 
0

尝试首先创建的字符串,然后设置在TextView文本。

1

试试这个

TextView.setText("You answered: " + correct + "correct\nYou answered: " + wrong + "incorrect"); 

注:按照惯例,应避免以大写字母命名的变量,尤其是名称已经是一个类名。考虑使用textView而不是TextView

-1

是不是通用的答案:

TextView.setText("You answered :" + " " + correct + "correct" + '\n'); 
// Lots of other intervening code 
TextView.append("You answered: " + " " + wrong + "incorrect"); 

此外,有很多不必要的字符串操作:

TextView.setText("You answered : " + correct + "correct\n"); 
// Lots of other intervening code 
TextView.append("You answered: " + wrong + " incorrect");