나는 이것을하려고한다 : 오늘 날짜, 이번 주, 이번 달 그리고 올해까지 객체 값 배열 (날짜 유형)을 정렬하고 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
당신이 지금까지 시도한 것을 보여주십시오 –
"오늘 날짜, 이번 주, 이번 달 또는 올해의 정렬"이란 무엇을 의미합니까? 질문에 구체적인 예를 들어 주시겠습니까? –