How to sort 20 RSS links by pubdate and display all in one

I am developing an Android application that gets data from at least 20 RSS links. But I need to display all the data of these links sorted by pubdate

.

I take data and store it in a database. Then I get the data from the database sorted by time. But this is inefficient and time consuming as it stores the data in the database and then retrieves it for display.

There is another way to store each RSS link in ArrayList

and merge 20 ArrayList

into one. And sort it out. But it also takes a long time.

How can I sort the data efficiently?

+3


source to share


1 answer


This might help you.



   Collections.sort(myFeedsList, new Comparator<RssItemModel>() {

        @Override
        public int compare(RssItemModel lhs, RssItemModel rhs) {
            SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
            try {
                Date date1 = formatter.parse(rhs.getPubDate());
                Date date2 = formatter.parse(lhs.getPubDate());
                return date1.compareTo(date2);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            return 0;
        }
    });

      

+2


source







All Articles