我已经筛选了一组对象,针对在EditText
中输入的特定字符串,现在我需要使用指定字符串的位置对该列表进行排序,我该怎么做?对象的搜索和排序列表
我已经做到了这一点
过滤功能
public void setFilter(String query) {
visibleList = new ArrayList<>();
query = query.toLowerCase(Locale.getDefault());
for (AccountProfile accountProfile : accountProfileList) {
if (accountProfile.getName().toLowerCase(Locale.getDefault())
.contains(query))
visibleList.add(accountProfile);
}
Collections.sort(visibleList, new AccountNameComparator());
}
AccountNameComparator
public class AccountNameComparator implements Comparator<AccountProfile> {
@Override
public int compare(AccountProfile first, AccountProfile second) {
return first.getName().compareTo(second.getName());
}
}
列表排序,但它是基于getname()
我需要重新梳理具有的特定子字符串的列表
只要改变比较方法,无论你需要的。 – 2016-12-29 06:02:44