开发者

Converting TextView to String (kind of) Android

开发者 https://www.devze.com 2023-01-19 18:20 出处:网络
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 Text开发者_如何学GoView into the sharefact string

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 Text开发者_如何学GoView 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!


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

String sharedFact = theFact.getText().toString();


TextView theFact = (TextView) findViewById(R.id.theFact);
String shareFact = theFact.getText().toString();
0

精彩评论

暂无评论...
验证码 换一张
取 消