TextWatcher接口中方法参数说明


简述:Android中EditText等控件监听文本内容的更改使用的是TextWatcher接口,但是官方文档对该接口中方法的参数说明很模糊,在此记录下对方法参数的认识(随认识的增加逐步完善)


public interface TextWatcher extends NoCopySpan {
    /**
     * This method is called to notify you that, within <code>s</code>,
     * the <code>count</code> characters beginning at <code>start</code>
     * are about to be replaced by new text with length <code>after</code>.
     * It is an error to attempt to make changes to <code>s</code> from
     * this callback.
     */
    public void beforeTextChanged(CharSequence s, int start,
                                  int count, int after);
    /**
     * 文本更改后的回调(使用时发现,小米手机,粘贴时前后都会默认加一个空格,
     * 造成参数的数字不准确,不知其他手机有无此情况,此处以键盘输入或删除为
     * 准。)
     * @param s
     *        更改以后现存的字符串
     * @param start
     *        新增字符:该值为新增字符所在的下标
     *        删除字符:该值为删掉字符所在的先
     * @param before
     *        新增字符:该值为0
     *        删除字符:该值为删掉的字符数
     * @param count
     *        新增字符:值为新增字符数
     *        删除字符:值为0
     */
    public void onTextChanged(CharSequence s, int start, int before, int count);

    /**
     * This method is called to notify you that, somewhere within
     * <code>s</code>, the text has been changed.
     * It is legitimate to make further changes to <code>s</code> from
     * this callback, but be careful not to get yourself into an infinite
     * loop, because any changes you make will cause this method to be
     * called again recursively.
     * (You are not told where the change took place because other
     * afterTextChanged() methods may already have made other changes
     * and invalidated the offsets.  But if you need to know here,
     * you can use {@link Spannable#setSpan} in {@link #onTextChanged}
     * to mark your place and then look up from here where the span
     * ended up.
     */
    public void afterTextChanged(Editable s);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值