setText(CharSequence, TextView.BufferType)和setText(CharSequence)有什么区别,我们什么时候应该使用它们?
发布于 2015-04-25 05:26:15
setText (CharSequence text)设置TextView的字符串值。鉴于
setText (CharSequence text, TextView.BufferType type) 设置此TextView要显示的文本,还设置它是否存储在可样式/可扩展缓冲区中,以及它是否可编辑。
所有BufferType选项包括:
例如:
myEditText.setText("This is new text from setText with BufferType EDITABLE.", TextView.BufferType.EDITABLE); 发布于 2015-04-25 06:02:00
您可以从文本视图代码中看到不同之处。
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的普通字符串。
发布于 2015-04-25 05:26:08
根据文档,区别在于setText(CharSequence,TextView.BufferType)还设置文本是否存储在可样式/可扩展缓冲区中,以及它是否可编辑。
http://developer.android.com/reference/android/widget/TextView.html#setText(java.lang.CharSequence)
https://stackoverflow.com/questions/29861302
复制相似问题