将TextView转换为String(种类)Android

Kee*_*son 8 string android textview

我的main.xml布局文件中有一个名为thefact的对象,即TextView.我还有一个名为sharefact的字符串.我想将TextView中的文本保存到sharefact字符串中.我做不到:

sharefact = thefact
Run Code Online (Sandbox Code Playgroud)

或类似的东西,因为它会要求我将sharefact转换为textview.

谢谢!

Tyl*_*eat 34

TextView theFact = (TextView) findViewById(R.id.theFact);
String shareFact = theFact.getText().toString();
Run Code Online (Sandbox Code Playgroud)

  • 别客气!在Android中享受有趣的编程! (4认同)

kik*_*iki 34

TextView退货中获取文本CharSequence.要转换CharSequenceString,使用toString()函数.

String sharedFact = theFact.getText().toString();
Run Code Online (Sandbox Code Playgroud)