0

I need the method or the action when the EditText changed. When the user write in EditText I want to have some action. How to do that?

foufi
  • 75
  • 2
  • 7

3 Answers3

0

I always do it with a TextWatcher, and overriding the afterTextChanged like this:

mEditText.addTextChangedListener(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) {
        String newText = editable.toString();
    }
});
Tiago A.
  • 2,568
  • 1
  • 22
  • 27
0

You can use View.setOnKeyListener(), see here.

Guillaume Brunerie
  • 4,676
  • 3
  • 24
  • 32
0

There are three methods you can register

beforeTextChanged
onTextChanged
afterTextChanged

Example reference: Counting Chars in EditText Changed Listener

Community
  • 1
  • 1
Priyank
  • 10,503
  • 2
  • 27
  • 25