我为一个ListView启用了setTextFilterEnabled文本过滤。 过滤正常工作,但是当我输入时会出现一个显示过滤文本的弹出窗口。请参见以下图片:
如何隐藏此弹出窗口或更改其在屏幕上的位置?
![ListView filter text popup](https://istack.dev59.com/Xz43y.webp)
http://blog.jamesbaca.net/?p=128
当你创建ArrayAdapter
来填充ListView
时,只需存储它的Filter引用,然后你就可以简单地修改ArrayAdapter
上的Filter,而不是ListView
。
*在Xamarin中,你只需要使用arrayAdapter.InvokeFilter("my text");
即可。
ContentAdapter adapter = new ContentAdapter(this, android.R.layout.simple_list_item_1,
s);
list1.setAdapter(adapter);
Filter f = adapter.getFilter();
public boolean onQueryTextChange(String newText) {
if (TextUtils.isEmpty(newText)) {
//list1.clearTextFilter();
f.filter(null);
} else {
//list1.setFilterText(newText.toString());
f.filter(newText);
}
return true;
}
很可能会弹出Filter.publishResults(CharSequence constraint, Filter.FilterResults results)。因此,您可能需要子类化Filter并覆盖它。
最好的问候。
Filter.publishResults(...)
方法来创建一个过滤器,这不是弹出窗口的地方。 - blahdiblah你好,正如Vatsal所提到的那样,你可以从适配器中创建一个过滤器。我解决这个问题的方法是创建了一个ArrayAdapter作为类变量。
// ...
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);
}
// ...
然后在 onQueryTextChange 或 onQueryTextSubmit 中,您可以通过这个类变量获取过滤器,如下所示:
//...
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;
}
//...