Why does TextView.getText()
return a CharSequence
instead of a String
?
(String is the implementation of the CharSequence)
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Because it might contain a Spannable
object. From the doc:
If
setText()
was called with an argument ofBufferType.SPANNABLE
orBufferType.EDITABLE
, you can cast the return value from this method toSpannable
orEditable
, respectively.
回答2:
it actually returns Editable
and not CharSequence
but you can store it in a String variable by calling toString()
on it.