我创建了适配器并创建了过滤器。适配器工作正常,但每次我调用 notifyDataSetChanged 时,AutoCompleteTextView 的下拉列表都会关闭,然后重新打开并提供新建议。
有什么办法可以避免关闭和重新打开下拉菜单?
编辑
class MyAdapter extends ArrayAdapter<String> {
private static final Filter NO_FILTER = new NoFilter();
private final Handler mHandler = new Handler();
public MyAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
}
public void updateList(String prefix) {
List<String> list = ...; //from web server;
clear();
foreach (String s : list)
add(s);
notifyDataSetChanged();
}
@Override
public Filter getFilter() {
return NO_FILTER;
}
private static class NoFilter extends Filter {
@Override
protected FilterResults performFiltering(CharSequence prefix) {
return new FilterResults();
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
}
}
}