InputFilter方法filter 解释
InputFilter
public abstract CharSequence filter (CharSequence source, int start, int end,Spanned dest, int dstart, int dend)
Added in API level 1This method is called when the buffer is going to replace the range dstart … dend
ofdest
with the new text from the rangestart … end
of source
. Return the CharSequence that you would like to have placed there instead, including an empty string if appropriate, ornull
to accept the original replacement. Be careful to not to reject 0-length replacements, as this is what happens when you delete text. Also beware that you should not attempt to make any changes todest
from this method; you may only examine it for context. Note: Ifsource is an instance ofSpanned
orSpannable
, the span objects in thesource should be copied into the filtered result (i.e. the non-null return value).copySpansFrom(Spanned, int, int, Class, Spannable, int)
can be used for convenience.
public abstract CharSequence filter (CharSequence source, int start, int end, Spanned dest, int dstart, int dend)
CharSequence source 为即将输入的字符串。source
int start source的start
int endsource的end start为0,end也可理解为source长度了
Spanned dest输入框中原来的内容,dest
int dstart, 要替换或者添加的起始位置,即光标所在的位置
int dend要替换或者添加的终止始位置,若为选择一串字符串进行更改,则为选中字符串 最后一个字符在dest中的位置。
return CharSequence
方法解释:在将Spanned dest中范围为dstart到dend的 用CharSequence source的start到end范围的替换。
返回你打算放入替换位置的CharSequence。包括空字符串,或者null来表示全部替换。
注意 不要屏蔽 长度为0 的替换(我:应该是dstart-dend = 0),因为当你删除text时也会调用这个方法。
另外也在这个方法中,不要试图对dest做任何改变,你只应检查它。(for context,context是翻译成上下文呢,还是不翻呢。。。。)
NOTE: 如果CharSequence source是Spanned或者Spannable的实例,在source中的Span实体应该被复制到被过滤的结果中(i.e.非空返回值)。可以用方法copySpansFrom(Spanned, int, int, Class, Spannable, int)进行复制。
更多相关文章
- 使用MediaPlayer播放音乐文件
- ImageView 长按保存
- Error inflating class androidx.recyclerview.widget.RecyclerV
- Android中正则表达式的常用判断
- Android之--电话归属地的悬浮框的…
- android 7.0 手机android.content.res.XmlResourceParser androi
- Android(安卓)多线程下载
- Android(安卓)UI开发第六篇——仿QQ的滑动Tab
- Android实现计数器功能