首页 > 代码库 > EditText设置文字改变时的监听

EditText设置文字改变时的监听

textWatcher = new TextChangeWatcher();

etQuerryInfo.addTextChangedListener(textWatcher);

/**
     * 文字改变类,文字改变时的监听
     */
    private class TextChangeWatcher implements TextWatcher{
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            rlQuerryInfo.setVisibility(View.VISIBLE);
            tvQuerryKey.setText(etQuerryInfo.getText().toString());
        }

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

        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    }

实现TextWatcher三个方法即可onTextChanged,beforeTextChanged,afterTextChanged

EditText设置文字改变时的监听