gpt4 book ai didi

android - 对 performFiltering 的约束在第一个字符上返回 null

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:53:59 28 4
gpt4 key购买 nike

我为 AutoCompleteTextView 编写了自定义过滤器。它工作正常,但是一件小事。 performFiltering 的约束在第一个字符上为空。这意味着只有当第二个字符被放入 AutoCompleteTextView 时,过滤过程才会开始。

这是过滤器的代码:

private Filter nameFilter = new Filter() {
public String convertResultToString(Object resultValue) {
String fullName = ((User)(resultValue)).facebookName;
return fullName;
}

@Override
protected FilterResults performFiltering(CharSequence constraint) {
if(constraint != null) {
suggestions.clear();
for (User friend : allFriends) {
if(friend.facebookName.toLowerCase().contains(constraint.toString().toLowerCase())){
suggestions.add(friend);
}
}
FilterResults filterResults = new FilterResults();
filterResults.values = suggestions;
filterResults.count = suggestions.size();
return filterResults;
} else {
return new FilterResults();
}
}

@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
ArrayList<User> filteredList = (ArrayList<User>) results.values;
if(results != null && results.count > 0) {
clear();
for (User friend : filteredList) {
add(friend);
}
notifyDataSetChanged();
}

}
};

谁能帮我解决这个问题,让过滤器从第一个字符开始过滤?

最佳答案

设置threshold到 1:

autoCompleteTextView.setThreshold(1)

Specifies the minimum number of characters the user has to type in the edit box before the drop down list is shown. When threshold is less than or equals 0, a threshold of 1 is applied.

关于android - 对 performFiltering 的约束在第一个字符上返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17137583/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com