Search code examples
androidlistviewsearchsearchviewtoast

Big black box on filterable searchview


I am following this tutorial and I see a big black box on filterable searchview. Almost like a toast. Any idea what it is and how to get rid of it? I searched the developer docs and could not find any info on it. When I remove parts of the onQueryTextChange, it stops filtering altogether. Many kind regards

http://www.coderzheaven.com/2013/06/01/create-searchview-filter-mode-listview-android/

enter image description here

See code:

    SearchView search = (SearchView) findViewById(R.id.search);
    ListView list = (ListView) findViewById(R.id.listView);

    final String[] mStrings = {"1", "2", "text", "more text", "more text here"};

    list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mStrings));
    list.setTextFilterEnabled(true);
    setupSearchView();

...

private void setupSearchView() {
    search.setIconifiedByDefault(false);
    search.setOnQueryTextListener(this);
    search.setSubmitButtonEnabled(false);
    search.setQueryHint("Search Here");
}

public boolean onQueryTextChange(String newText) {
    if (TextUtils.isEmpty(newText)) {
        list.clearTextFilter();
    } else {
        list.setFilterText(newText.toString());

    }
    return true;
}

public boolean onQueryTextSubmit(String query) {
    return false;
}

Solution

  • Change list.setTextFilterEnabled(true); to list.setTextFilterEnabled(false);.

    Also change your onQueryTextChange to the below:

    @Override
    public boolean onQueryTextChange(String newText) {
        CustomAdapter customAdapter = (customAdapter)list.getAdapter();
        Filter filter = customAdapter.getFilter();
    
    
        filter.filter(newText);
        return true;
    }
    

    According to Google,

    setTextFilterEnabled Enables or disables the type filter window. If enabled, typing when this view has focus will filter the children to match the users input.