cptKopernikus cptKopernikus - 5 months ago 15
Java Question

EditText changedListener is not getting called

I use an

EditText
to filter some values in an
ListView
.

It works so far, but I have one problem. First my code:

final EditText mEditText = (EditText) this.findViewById(R.id.filterEditText);
mEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}

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

@Override
public void afterTextChanged(Editable editable) {
String mFilter = editable.toString();
mListViewUpdater.setFilter(mFilter);
Log.d("Editable", editable.toString());
}
}


The method
afterTextChanged()
gets called when I type something in and the filter is applied and works.

But if I delete everything in the
EditText
, the
ListView
stays at it last filtered state until I close the keyboard and then it shows all values again.

Is there a way to show all values eevn if the EditText is empty but the Keyboard is not collapsed?

Best regards!

Answer

Put all of your code into the onTextChanged() method instead of the afterTextChanged() method.