0

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!

cptKopernikus
  • 72
  • 2
  • 8
  • Possible duplicate of [Android EditText delete(backspace) key event](http://stackoverflow.com/questions/4886858/android-edittext-deletebackspace-key-event) – nicobatu Jul 01 '16 at 22:00

1 Answers1

-1

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

Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
Asif Patel
  • 1,744
  • 1
  • 20
  • 27