Reputation: 14453
I setTextFilterEnabled
for text filtering a ListView
. Filtering is working fine, but a popup window showing the filter text appears when I type. See image:
How can I hide this popup or change its position on the screen?
Upvotes: 3
Views: 2220
Reputation: 1
Hi as Vatsal mentioned you can create a filter from the adapter. So the way in which I solved this was that I created an 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 the onQueryTextChange or onQueryTextSubmit you can get the filter like so
//...
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;
}
//...
Upvotes: 0
Reputation: 1156
Create a filter , ( you may be using 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 the 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;
}
Upvotes: 3
Reputation: 432
I have found easier solution that works for me on this blog:
http://blog.jamesbaca.net/?p=128
When you create ArrayAdapter
to populate ListView
, just store reference to its Filter and then you can simply modify Filter on ArrayAdapter
instead of ListView
.
*In Xamarin you can just use arrayAdapter.InvokeFilter("my text");
Upvotes: 4
Reputation: 1834
Filter.publishResults(CharSequence constraint, Filter.FilterResults results) is probably what pops up. And therefore you probably need to subclass Filter and override it.
Best regards.
Upvotes: 1