Skip to content Skip to sidebar Skip to footer

Sort Listview By Date Android

I got a custom listview which contains info about tv shows, ie. show title, last episode, last episode date, next episode, next episode date an so on. Now I want to sort the listv

Solution 1:

Store your dates as strings in yyyy-MM-dd format. Comparing two date strings in this format will always guarantee getting an ascending/descending sort order.

Solution 2:

Same as you are sorting on the basis of title,can be done with dates also. Example:

// sort by datepublicintcompareTo(NewsDetails another) 
    {
        if (another == null) return1;
        // sort descending, most recent firstreturn another.date.compareTo(date);
    }

Solution 3:

Considering that you have all the data in ArrayList and in you have two ArrayLists, one contains the date and its corresponding indexes in another ArrayList have other details about the TV Shows, you're supposed to be sorting both the ArrayLists on the basis of Dates stored in the ArrayList that holds date, and then provide the ListView adapter with it.

You can construct a Date object with the date time and then sort them.

Was this helpful?

Post a Comment for "Sort Listview By Date Android"