0

I'm trying to make a layout with two AutoCompletetextViews, the problem is how to differentiate the .addTextChangedListener(this) from each one.

I mean an EditText can be differentiated by its own View.getId(), and do different things depend on this Id, but I don't know how to do it with AutoCompleteTextViews.

Tikhon Jelvis
  • 67,485
  • 18
  • 177
  • 214
Arnau S
  • 3
  • 1

1 Answers1

0

Adding this to the listener is jsut optional implementation - basically you need to add an instance of something that is implementing TextWatcher, and many people tend to do that making the Activity class implement the interface. However, in your case it might be easier if you have two internal classes implementing the interface in the way you need it.

Basically you can add listeners even with class defined into the addTextChangedListener method call like that:

editText.addTextChangedListener(new TextWatcher() {

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

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

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
Boris Strandjev
  • 46,145
  • 15
  • 108
  • 135