0

我有一个 textView,我想同时显示两个不同的变量,每个变量都在一行上。这是我到目前为止所拥有的

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

这仅显示最后一行,而不是 textView 中的两行代码。谁能告诉我如何在两个不同的行上同时在同一个 textView 中显示这两个?非常感激。

4

5 回答 5

2

使用此剪辑代码:

TextView.setText("You answered :" + " " + correct + "correct\n" +"You answered: " + " " + wrong + "incorrect");
于 2013-04-11T05:14:09.780 回答
2
String text = "You answered :" + " " + correct + "correct\n" +"You answered: " + " " + wrong + "incorrect";
TextView.setText(text);
于 2013-04-11T05:15:04.663 回答
1

试试这个

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

注意:按照惯例,您应该避免使用大写字母命名变量,特别是如果名称已经是类名。考虑使用textView而不是TextView.

于 2013-04-11T05:15:14.157 回答
0

尝试先创建字符串,然后在TextView.

于 2013-04-11T05:14:51.437 回答
-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");
于 2013-04-11T05:19:51.553 回答