我在我的main.xml布局文件中有一个名为thefact的TextView对象。我还有一个名为sharefact的字符串。我想把TextView中的文本保存到sharefact字符串中。但是我不能这样做:
sharefact = thefact
或者类似的内容,因为它要我将sharefact转换为textview。
谢谢!
从 TextView
获取文本会返回 CharSequence
。要将 CharSequence
转换为 String
,需要使用 toString()
函数。
String sharedFact = theFact.getText().toString();
TextView theFact = (TextView) findViewById(R.id.theFact);
String shareFact = theFact.getText().toString();