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



更多相关文章

  1. 使用MediaPlayer播放音乐文件
  2. ImageView 长按保存
  3. Error inflating class androidx.recyclerview.widget.RecyclerV
  4. Android中正则表达式的常用判断
  5. Android之--电话归属地的悬浮框的…
  6. android 7.0 手机android.content.res.XmlResourceParser androi
  7. Android(安卓)多线程下载
  8. Android(安卓)UI开发第六篇——仿QQ的滑动Tab
  9. Android实现计数器功能

随机推荐

  1. ubuntu连接android设备(附最简单方法)
  2. How to destroy an Activity in android
  3. Android Non-UI to UI Thread Communicat
  4. Android 获得屏幕分辨率
  5. android之实现各个组件点击事件监听
  6. CMAKE 在Linux下 构建android 编译、打包
  7. 短信接收--Android彩信的接收流程(应用层)
  8. Process 'command 'C:\zssinstallsoft\
  9. android 主线程和子线程之间的消息传递
  10. Android学习中遇到的问题及解决方案