10

I have an object on my main.xml layout file called thefact that is TextView. I also have a string called sharefact. I want to save what text is in the TextView into the sharefact string. I can't do:

sharefact = thefact

Or anything similar to that because it would want me to convert sharefact into a textview.

Thanks!

Keenan Thompson
  • 980
  • 3
  • 13
  • 31

2 Answers2

39

Getting text from a TextView returns CharSequence. To convert CharSequence to String, toString() function is used.

String sharedFact = theFact.getText().toString();
Damian Kozlak
  • 7,065
  • 10
  • 45
  • 51
kiki
  • 13,627
  • 17
  • 49
  • 62
37
TextView theFact = (TextView) findViewById(R.id.theFact);
String shareFact = theFact.getText().toString();
Tyler Treat
  • 14,640
  • 15
  • 80
  • 115