(种)转换的TextView为String的Andr​​oidString、TextView、oid、Andr

2023-09-05 01:16:23 作者:初见倾心

我有我的main.xml布局文件的对象称为thefact是TextView的。我也有一个名为sharefact字符串。我想保存在TextView中进入sharefact字符串文本内容。我不能做的:

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

或者什么类似,因为这会要我转换sharefact成一个TextView。

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

谢谢!

推荐答案

这是一个TextView Geeting文本返回的CharSequence。要转换的CharSequence为String,的toString()函数。

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

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