首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >与setText(CharSequence,TextView.BufferType)和setText(CharSequence)不同

与setText(CharSequence,TextView.BufferType)和setText(CharSequence)不同
EN

Stack Overflow用户
提问于 2015-04-25 05:15:32
回答 3查看 7K关注 0票数 5

setText(CharSequence, TextView.BufferType)setText(CharSequence)有什么区别,我们什么时候应该使用它们?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-04-25 05:26:15

代码语言:javascript
复制
setText (CharSequence text)

设置TextView的字符串值。鉴于

代码语言:javascript
复制
setText (CharSequence text, TextView.BufferType type) 

设置此TextView要显示的文本,还设置它是否存储在可样式/可扩展缓冲区中,以及它是否可编辑。

所有BufferType选项包括:

  1. TextView.BufferType.EDITABLE
  2. TextView.BufferType.NORMAL
  3. TextView.BufferType.SPANNABLE

例如:

代码语言:javascript
复制
myEditText.setText("This is new text from setText with BufferType EDITABLE.",  TextView.BufferType.EDITABLE); 
票数 1
EN

Stack Overflow用户

发布于 2015-04-25 06:02:00

您可以从文本视图代码中看到不同之处。

代码语言:javascript
复制
  if (type == BufferType.EDITABLE || getKeyListener() != null ||
            needEditableForNotification) {
        createEditorIfNeeded();
        Editable t = mEditableFactory.newEditable(text);
        text = t;
        setFilters(t, mFilters);
        InputMethodManager imm = InputMethodManager.peekInstance();
        if (imm != null) imm.restartInput(this);
    } else if (type == BufferType.SPANNABLE || mMovement != null) {
        text = mSpannableFactory.newSpannable(text);
    } else if (!(text instanceof CharWrapper)) {
        text = TextUtils.stringOrSpannedString(text);
    }

默认情况下,如果使用普通的setText,则采用TextView.BufferType.NORMAL的类型,这基本上是SpannedString的普通字符串。

票数 1
EN

Stack Overflow用户

发布于 2015-04-25 05:26:08

根据文档,区别在于setText(CharSequence,TextView.BufferType)还设置文本是否存储在可样式/可扩展缓冲区中,以及它是否可编辑。

http://developer.android.com/reference/android/widget/TextView.html#setText(java.lang.CharSequence)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29861302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档