亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

TextWatcher用于多個EditText

TextWatcher用于多個EditText

蕭十郎 2019-12-17 14:41:21
我想TextWatcher為多個EditText字段實現接口。目前我正在使用:text1.addTextChangedListener(this);text2.addTextChangedListener(this);然后覆蓋我的Activity中的方法:public void afterTextChanged(Editable s) {}public void beforeTextChanged(CharSequence s, int start, int count, int after) {}public void onTextChanged(CharSequence s, int start, int before, int count) { // do some operation on text of text1 field // do some operation on text of text2 field }但這工作正常,但我正在尋找其他方法,以便可以明確確定當前關注的EditText領域SoftKeyboard。
查看完整描述

3 回答

?
尚方寶劍之說

TA貢獻1788條經驗 獲得超4個贊

我會這樣:


@Override

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);


    EditText e = new EditText(this);

    e.addTextChangedListener(new CustomTextWatcher(e));

}


private class CustomTextWatcher implements TextWatcher {

    private EditText mEditText;


    public CustomTextWatcher(EditText e) { 

        mEditText = e;

    }


    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }


    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }


    public void afterTextChanged(Editable s) {

    }

}


查看完整回答
反對 回復 2019-12-17
  • 3 回答
  • 0 關注
  • 616 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號