TextWatcher使用

作者: hehe_Android | 来源:发表于2016-09-01 11:42 被阅读466次

    TextWatcher 是一个集成NoCopySpan的interface
    有三个方法beforeTextChanged,onTextChanged,afterTextChanged
    原始字符串如下:
    这是初始值,不能撤销的值

    首先尝试删除字符串:

    1111111.png

    1.public void beforeTextChanged(CharSequence s, int start, int count, int after);

    s:删除之前的所有字符串
    
    start:删除字符串的起始位置和onTextChanged的start 一般相同
    
    count:删除字符串的数量
    
    after:替换或者添加字符串的数量,删除时一般为0
    

    2.public void onTextChanged(CharSequence s, int start, int before, int count);

    s:删除之后的字符串
    
    start:删除字符串的起始位置和beforeTextChanged的start 一般相同
    
    after:
    
    count:删除动作时为0
    

    添加字符串字符串:

    222222.png

    1.public void beforeTextChanged(CharSequence s, int start, int count, int after);

    s:添加之前的所有字符串
    
    start:添加字符串的起始位置和onTextChanged的start 一般相同
    
    count:数量为0
    
    after:添加字符串的数量
    

    2.public void onTextChanged(CharSequence s, int start, int before, int count);

    s:添加之后的字符串
    
    start:添加字符串的起始位置和beforeTextChanged的start 一般相同
    
    before:添加动作时为0
    
    count: 添加的数量
    

    替换字符串字符串:

    44444444.png

    1.public void beforeTextChanged(CharSequence s, int start, int count, int after);

    s:添加之前的所有字符串
    
    start:替换字符串的起始位置和onTextChanged的start 一般相同
    
    count:替换之前的数量
    
    after:替换之后的字符串数量
    

    2.public void onTextChanged(CharSequence s, int start, int before, int count);

    s:替换之后的字符串
    
    start:替换字符串的起始位置和beforeTextChanged的start 一般相同
    
    before:替换之前的数量(被替换的字符串)
    
    count: 替换之后的字符串数量(替换的字符串)
    

    相关文章

      网友评论

        本文标题:TextWatcher使用

        本文链接:https://www.haomeiwen.com/subject/vbvcettx.html