将 TextView 转换为字符串(某种)Android [英] Converting TextView to String (kind of) Android
本文介绍了将 TextView 转换为字符串(某种)Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 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
获取文本返回 CharSequence
.要将 CharSequence
转换为 String
,需要使用 toString()
函数.
Getting text from a TextView
returns CharSequence
. To convert CharSequence
to String
, toString()
function is used.
String sharedFact = theFact.getText().toString();
这篇关于将 TextView 转换为字符串(某种)Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文