Android显示多个变量textView

时间:2013-04-11 05:11:58

标签: android textview

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

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

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

5 个答案:

答案 0 :(得分:1)

使用此剪辑代码:

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

答案 1 :(得分:1)

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

答案 2 :(得分:1)

试试这个

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

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

答案 3 :(得分:0)

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

中设置文本

答案 4 :(得分:-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");