I am currently using AsyncTask()
to fetch rss feeds from 3 different xmls like this,
for (int i = 0; i < urls.length; i++) {
GetDates currentBlog = new GetDates(i);
currentBlog.execute();
}
and I am using DOM parser to read dates from each xml feed like this,
eElement.getElementsByTagName(pubDate).item(0).getTextContent())
all the dates are fetched as String
and then converted into Date
object using SimpleDateFormatter
and then stored in ArrayList
.
Since the dates are fetched from 3 different feeds and stored in ArrayList
, the ArrayList
isn't sorted,
Here is the data in the ArrayList
// First Feed
Sun Jan 18 22:07:35 GMT+05:00 2015
Sat Jan 17 06:02:05 GMT+05:00 2015
Sat Jan 17 01:34:10 GMT+05:00 2015
Fri Jan 16 22:58:32 GMT+05:00 2015
Fri Jan 16 01:56:06 GMT+05:00 2015
Thu Jan 15 21:46:18 GMT+05:00 2015
Thu Jan 15 01:57:09 GMT+05:00 2015
Wed Jan 14 22:47:15 GMT+05:00 2015
Wed Jan 14 01:05:22 GMT+05:00 2015
Tue Jan 13 21:59:15 GMT+05:00 2015
Tue Jan 13 17:14:11 GMT+05:00 2015
Tue Jan 13 15:03:06 GMT+05:00 2015
Tue Jan 13 12:31:12 GMT+05:00 2015
Tue Jan 13 06:01:12 GMT+05:00 2015
// Second Feed Starts here
Sat Jan 17 01:56:00 GMT+05:00 2015
Fri Jan 16 19:23:30 GMT+05:00 2015
Fri Jan 16 05:07:00 GMT+05:00 2015
Fri Jan 16 09:07:00 GMT+05:00 2015
Wed Jan 14 02:44:00 GMT+05:00 2015
// Third Feed Starts here
Sat Jan 17 01:56:00 GMT+05:00 2015
Fri Jan 16 19:23:30 GMT+05:00 2015
Fri Jan 16 05:07:00 GMT+05:00 2015
Fri Jan 16 09:07:00 GMT+05:00 2015
Wed Jan 14 02:44:00 GMT+05:00 2015
I wanted to sort that ArrayList
so I used Comparator
class to do that, but the problem is that I have to wait until the data from all 3 feeds are loaded before I can start sorting.
this is what i am doing,
if (allfeedsareloaded == true)
// Start sorting here
I learned that I can use TreeSet
class to keep the object sorted at all times but I have no clue how to use it?
Is there any other way to keep data sorted at all times without using a lot of memory or time ?