정렬할 ArrayList 입니다.

List<VideoEntry> list = new ArrayList<>();
Collections.sort(list);

리스트에 저장된 VideoEntry 클래스 입니다.

Comparable을 상속받아 compareTo함수의 내용을 써줍니다.

public class VideoEntry implements Comparable<VideoEntry> {
    public String text;
    public String videoId;
    public String time;

    public VideoEntry(String text, String videoId, String time) {
        this.text = text;
        this.videoId = videoId;
        this.time = time;
    }

    //오름차순
    @Override
    public int compareTo(VideoEntry entry) {
        return this.time.compareTo(entry.time);
    }

    //내림차순
    @Override
    public int compareTo(VideoEntry entry) {
        return entry.time.compareTo(this.time);
    }
}

'Android' 카테고리의 다른 글

[Android] APK 만들기  (0) 2019.03.30
[Android] '돌아가기' 버튼 구현  (0) 2019.03.29
[Android] Tab 사용법  (0) 2019.03.27
[Android] RecyclerView 예제  (0) 2019.03.26
[Android] YouTube Api call Url  (0) 2019.03.22

+ Recent posts