Hello Android developers,
I've got a problem with the Android SearchView widget. What I'm trying to do is to attach a "live" text filter to my ListView (text input automatically refreshes filter results). It works actually fine and it was no huge effort to get it working on my ListActivity with these lines:
private SearchView listFilter;
this.listFilter = (SearchView) findViewById(R.id.listFilter);
this.listFilter.setOnQueryTextListener(this);
this.listFilter.setSubmitButtonEnabled(false);
this.getListView().setOnItemClickListener(this);
this.getListView().setTextFilterEnabled(true);
// from OnQueryTextListener
public boolean onQueryTextChange(String newText) {
if (newText.isEmpty()) {
this.getListView().clearTextFilter();
} else {
this.getListView().setFilterText(newText);
}
return true;
}
And here the xml widget declaration
<SearchView
android:id="@+id/listFilter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:iconifiedByDefault="false"
android:queryHint="enter text to filter" />
Now what my problem is that every time I enter text into the SearchView, a strange text field pops up instantly showing the same text as I just entered which is kind of useless since I can see my input in the SearchView itself and it partly blocks the sight on my list entries, which is just annoying.
Is there any way to prevent that text field from popping up on typing into the SearchView? I couldn't find any property neither on the xml defined widget options nor on the java class reference.
I know there is another way to provide the filter functionality by using EditText and TextWatcher, but then I have to handle the filtering all by myself and couldn't profit from the SearchView handling it for me.
Any suggestions are appreciated. Best regards
Felix