InputFilter方法filter 解释


InputFilter

public abstract CharSequence filter (CharSequence source, int start, int end,Spanned dest, int dstart, int dend)
Added in API level 1

This 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)进行复制。



  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值