gpt4 book ai didi

java - 未经检查的转换问题

转载 作者:行者123 更新时间:2023-11-29 19:27:23 26 4
gpt4 key购买 nike

<分区>

我有一个自动完成适配器,但我收到此警告:未经检查的转换:“java.lang.Object”到“java.util.ArrayList”

这是我在其中获取过滤器的代码:

private final Filter nameFilter = new Filter() {
@Override
public CharSequence convertResultToString(Object resultValue) {
return ((UserNameAndPic) resultValue).getUserName();
}

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

@Override
protected void publishResults(CharSequence constraint, Filter.FilterResults results) {
List<UserNameAndPic> filterList = (List<UserNameAndPic>) results.values;
if (results.count > 0) {
clear();
for (UserNameAndPic people : filterList) {
add(people);
notifyDataSetChanged();
}
}
}
};

线路有问题:

List<UserNameAndPic> filterList = (ArrayList<UserNameAndPic>) results.values;

我知道这只是一个警告,我可以抑制它,但我想避免转换而不是抑制警告。有谁知道该怎么做吗?

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