1. 程式人生 > >TextWatcher介面中方法引數說明

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);