0

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.

5 Answers 5

2
String text = "You answered :" + " " + correct + "correct\n" +"You answered: " + " " + wrong + "incorrect";
TextView.setText(text);
Sign up to request clarification or add additional context in comments.

Comments

2

Using this snip code:

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

Comments

1

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.

Comments

0

Try create the String first then set the text in the TextView.

Comments

-1

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");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.