简单记一下,以前没怎么用过。
EditText View的getText直接返回的就是 Editable
而 TextView则是getEditableText才返回 Editable。
还有就是注释所说,
* Replaces the specified range (<code>st…en</code>) of text in this
* Editable with a copy of the slice <code>start…end</code> from
* <code>source</code>. The destination slice may be empty, in which case
* the operation is an insertion, or the source slice may be empty,
* in which case the operation is a deletion.
replace 在 没有选中内容时 表现为 insert操作,
replace/insert 的String 参数 不能为空.
android.text
接口 Editable
所有超级接口:
Appendable, CharSequence, GetChars, Spannable, Spanned
所有已知实现类:
SpannableStringBuilder
public interface Editable extends CharSequence, GetChars, Spannable, Appendable
This is the interface for text whose content and markup can be changed (as opposed to immutable text like Strings). If you make a DynamicLayout of an Editable, the layout will be reflowed as the text is changed.
嵌套类摘要 | |
|
|
字段摘要 |
从接口 android.text.Spanned 继承的字段 |
|
方法摘要 | |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
从接口 android.text.GetChars 继承的方法 |
|
从接口 android.text.Spannable 继承的方法 |
|
从接口 android.text.Spanned 继承的方法 |
|
从接口 java.lang.CharSequence 继承的方法 |
|
方法详细信息 |
replace
Editable replace(int st, int en, CharSequence source, int start, int end)
Replaces the specified range (
st…en
) of text in this Editable with a copy of the slice
start…end
from
source
. The destination slice may be empty, in which case the operation is an insertion, or the source slice may be empty, in which case the operation is a deletion.
Before the change is committed, each filter that was set with setFilters(android.text.InputFilter[]) is given the opportunity to modify the source
text.
If source
is Spanned, the spans from it are preserved into the Editable. Existing spans within the Editable that entirely cover the replaced range are retained, but any that were strictly within the range that was replaced are removed. As a special case, the cursor position is preserved even when the entire range where it is located is replaced.
返回:
a reference to this object.
replace
Editable replace(int st, int en, CharSequence text)
另请参见:
replace(int, int, CharSequence, int, int)
insert
Editable insert(int where, CharSequence text, int start, int end)
另请参见:
replace(int, int, CharSequence, int, int)
insert
Editable insert(int where, CharSequence text)
另请参见:
replace(int, int, CharSequence, int, int)
delete
Editable delete(int st, int en)
另请参见:
replace(int, int, CharSequence, int, int)
append
Editable append(CharSequence text)
指定者:
接口
Appendable
中的
append
参数:
text
- the character sequence to append.
返回:
this
Appendable
.
另请参见:
replace(int, int, CharSequence, int, int)
append
Editable append(CharSequence text, int start, int end)
指定者:
接口
Appendable
中的
append
参数:
text
- the character sequence to append.
start
- the first index of the subsequence of
csq
that is appended.
end
- the last index of the subsequence of
csq
that is appended.
返回:
this
Appendable
.
另请参见:
replace(int, int, CharSequence, int, int)
append
Editable append(char text)
指定者:
接口
Appendable
中的
append
参数:
text
- the character to append.
返回:
this
Appendable
.
另请参见:
replace(int, int, CharSequence, int, int)
clear
void clear()
另请参见:
Note that this clears the text, not the spans; use {@link #clearSpans} if you need that.
clearSpans
void clearSpans()
setFilters
void setFilters(InputFilter[] filters)
getFilters
InputFilter[] getFilters()
Returns the array of input filters that are currently appliedto changes to this Editable.