Reputation: 311
I have a textView and I want to display two different variables at the same time, each on one line. Here is what I have so far
TextView.setText("You answered :" + " " + correct + "correct" + '\n');
TextView.setText("You answered: " + " " + wrong + "incorrect");
this only displays the last line and not both lines of code in the textView. Can anyone tell me how i can go about displaying both of these in the same textView at the same time on 2 different lines? Much appreciated.
Upvotes: 0
Views: 1245
Reputation: 6447
Using this snip code:
TextView.setText("You answered :" + " " + correct + "correct\n" +"You answered: " + " " + wrong + "incorrect");
Upvotes: 2
Reputation: 15009
Isn't the generic answer:
TextView.setText("You answered :" + " " + correct + "correct" + '\n');
// Lots of other intervening code
TextView.append("You answered: " + " " + wrong + "incorrect");
In addition, there is a lot of unnecessary string operations:
TextView.setText("You answered : " + correct + "correct\n");
// Lots of other intervening code
TextView.append("You answered: " + wrong + " incorrect");
Upvotes: -1
Reputation: 12656
Try this:
TextView.setText("You answered: " + correct + "correct\nYou answered: " + wrong + "incorrect");
Note: By convention, you should avoid naming variables with capital letters, especially if the name is already a class name. Consider using textView
instead of TextView
.
Upvotes: 1
Reputation: 13785
String text = "You answered :" + " " + correct + "correct\n" +"You answered: " + " " + wrong + "incorrect";
TextView.setText(text);
Upvotes: 2