Sander
Sander

Reputation: 714

How can you setText of a TextView in another TextView?

I want the text I have in TextView1 to be displayed in TextView2, for example:

TextView1.setText("hello");

TextView2.setText(ContentOf.TextView1)

What do I have to type instead of

 "ContentOf.TextView1"

?

Upvotes: 1

Views: 92

Answers (2)

Hamid Shatu
Hamid Shatu

Reputation: 9700

Get the text of TextView1 with getText() and set it to the TextView2 as follows...

TextView1.setText("hello");

TextView2.setText(TextView1.getText())

Upvotes: 4

Swayam
Swayam

Reputation: 16364

TextView1.getText() returns a CharacterSequence which is the text set in the corresponding TextView.

So,

TextView2.setText(TextView1.getText().toString());

Or even just,

TextView2.setText(TextView1.getText());

Upvotes: 1

Related Questions