控件EditText

(一)监听EditText输入内容变化

EditText.addTextChangedListener(textWatcher);

//EditText change listener
    //此方法会在初始化时自动执行一次
    private TextWatcher textWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    };

 

(二)EditText与软键盘交互

   //when the entry key is pressed   //此方法会执行两次,注意控制
        EditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                       return false;
            }
        });

你可能感兴趣的:(EditText)