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()
に基づいており、この
フィルタ機能を行っています
の特定の部分文字列を持つリストsort that list with the position of the specified string
に
以下のようにちょうどあなたが必要とするものは何でもと比較する方法を変更します。 –