How to hide filter popup in ListView in Android?

I setTextFilterEnabled

for text filtering a ListView

. The filtering works fine, but as you type, a popup appears with the filter text. See Image:

ListView filter text popup

How can I hide this popup or change its position on the screen?

+3


source to share


4 answers


Filter.publishResults (CharSequence constraint, Filter.FilterResults results) is probably what pops up. And so you probably need to subclass Filter and override it.



Sincerely.

+1


source


I found an easier solution that works for me on this blog:

http://blog.jamesbaca.net/?p=128



When you create ArrayAdapter

to fill ListView

, just keep a link to your Filter and then you can just change Filter on ArrayAdapter

instead ListView

.

* In Xamarin, you can simply use arrayAdapter.InvokeFilter("my text");

+4


source


Create a filter (you can use a different adapter)

ContentAdapter  adapter = new ContentAdapter(this, android.R.layout.simple_list_item_1,
            s);
    list1.setAdapter(adapter);
    Filter f = adapter.getFilter();

      

Then use filter inside 'onQueryTextChange' instead of commented code

public boolean onQueryTextChange(String newText) {
        if (TextUtils.isEmpty(newText)) {

            //list1.clearTextFilter();
            f.filter(null);
        } else {
            //list1.setFilterText(newText.toString());
            f.filter(newText);

        }
        return true;
    }

      

+3


source


Hi like Vatsal said you can create a filter from an adapter. So I figured I created the ArrayAdapter as a class variable.

// ...
private void setListAdapter() {
    List<Word> words = Dictionary.getInstance(this).getWords();

    arrayAdapter = new ArrayAdapter<>(
            this,
            android.R.layout.simple_list_item_activated_1,
            android.R.id.text1,
            words);
    // Sets the List Adapter that we are using
    this.setListAdapter(arrayAdapter);
}
// ...

      

then from this class variable in onQueryTextChange or onQueryTextSubmit you can get the filter this way

//...
public boolean onQueryTextChange(String query) {
    // By doing this it removes the popup completely which was arising from using the this.getListView().setFilterText(query) method
    arrayAdapter.getFilter().filter(query);

    return true;
}
//...

      

0


source







All Articles