What is the return type of TextView.getText() in android?

亡梦爱人 提交于 2019-12-11 12:36:16

问题


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 of BufferType.SPANNABLE or BufferType.EDITABLE, you can cast the return value from this method to Spannable or Editable, respectively.




回答2:


it actually returns Editable and not CharSequence but you can store it in a String variable by calling toString() on it.



来源:https://stackoverflow.com/questions/21915797/what-is-the-return-type-of-textview-gettext-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!