私はこれをやろうとしています:今日の日付、今週、今月と今年のオブジェクト値の配列(日付タイプ)をソートし、Comparatorクラスを使って日付の配列を降順または昇順にソートする方法は分かっていますが私は、今日の日付、今週、今月または今年までに言ったように、配列をどのように並べ替えるべきかわかりません。写真のリストをフィルタリングする方法 - android?
private void sortTopicsByDate() {
Collections.sort(topics, new Comparator<Topic>() {
@Override
public int compare(Topic o1, Topic o2) {
return o1.getCreatedTime().compareTo(o2.getCreatedTime());
}
});
}
UPDATE(今日作成された写真をフィルタリングリスト)
private List<Topic> getFilteredTopics() {
List<Topic> filteredList = new ArrayList<>();
Date now = new Date(); // today date
Calendar cal = Calendar.getInstance();
Calendar getCal = Calendar.getInstance();
cal.setTime(now);
int nYear = cal.get(Calendar.YEAR);
int nMonth = cal.get(Calendar.MONTH);
int nDay = cal.get(Calendar.DAY_OF_MONTH);
if (topics != null) {
for (Topic topic : topics) {
getCal.setTime(topic.getCreatedTime());
int year = getCal.get(Calendar.YEAR);
int month = getCal.get(Calendar.MONTH);
int day = getCal.get(Calendar.DAY_OF_MONTH);
if (nDay == day && month == nMonth) {
filteredList.add(topic);
}
}
}
return filteredList;
}
"this"とは何ですか? – shmosel
これまでに試したことを示してください –
「今日の日付、今週、今月または今年の並べ替え」とはどういう意味ですか?あなたの質問に具体的な例を追加できますか? –