从 TextView 获取文本
Get the text from a TextView
如何从文本视图中获取字符串形式的文本?
我试过了:
myTextView.getText();
但是没用。
要从 TextView 获取文本,请使用 .getText()
,然后使用 .toString()
将其转换为字符串
String s = myTextview.getText().toString();
从字符串中获取文本的正确方法几乎就是这样!你只是忘了使用 toString()
因此,要将其作为字符串获取,您需要做的就是
myTextview.getText().toString();
这将为您提供所需的字符串(然后随心所欲地使用它)。
getText() 不起作用的原因是它returns 一个可编辑对象,而不是一个字符串。
This is the interface for text whose content and markup can be changed
(as opposed to immutable text like Strings). If you make a
DynamicLayout of an Editable, the layout will be reflowed as the text
is changed.
String mString =myTextView.getText() + " ";
通过 getText() 方法从 Textview 中获取文本,然后将其转换为字符串....
如何从文本视图中获取字符串形式的文本?
我试过了:
myTextView.getText();
但是没用。
要从 TextView 获取文本,请使用 .getText()
,然后使用 .toString()
String s = myTextview.getText().toString();
从字符串中获取文本的正确方法几乎就是这样!你只是忘了使用 toString()
因此,要将其作为字符串获取,您需要做的就是
myTextview.getText().toString();
这将为您提供所需的字符串(然后随心所欲地使用它)。
getText() 不起作用的原因是它returns 一个可编辑对象,而不是一个字符串。
This is the interface for text whose content and markup can be changed (as opposed to immutable text like Strings). If you make a DynamicLayout of an Editable, the layout will be reflowed as the text is changed.
String mString =myTextView.getText() + " ";
通过 getText() 方法从 Textview 中获取文本,然后将其转换为字符串....