setText(CharSequence, TextView.BufferType)
和setText(CharSequence)
有什么区别?我们应该在什么情况下使用它们?
setText (CharSequence text)
setText (CharSequence text, TextView.BufferType type)
例如:
myEditText.setText("This is new text from setText with BufferType EDITABLE.", TextView.BufferType.EDITABLE);
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。
setText(CharSequence,TextView.BufferType)
还设置了文本是否存储在可样式化/可跨度缓冲区中以及是否可编辑。
http://developer.android.com/reference/android/widget/TextView.html#setText(java.lang.CharSequence)