如何从 TextView 中获取字符串形式的文本?
我试过:
myTextView.getText();
但是没用。
最佳答案
从字符串中获取文本的正确方法几乎就是这样!你只是忘了使用 toString()
因此,要将其作为字符串获取,您需要做的就是
myTextview.getText().toString();
这将为您提供所需的字符串(然后随意使用它)。
getText() 不起作用的原因是因为它返回一个 Editable 对象,而不是一个 String。
来自documentation :
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.
关于android - 从 TextView 获取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29980615/