Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 148
Registered: ‎10-30-2010
My Device: Bold 9930
My Carrier: Verizon

Ordering ListView items by date

I'm using a ListView that displays an RSS feed. How can I get it to show in order by date? The format is "Thu, 07 Feb 2013 18:58:00 GMT". I think by default it would have them come in with the newest first (how I want it) but it has some form of SORTING enabled that cunks it by alphabetical order with days.

 

So for example it will show an order of entries by something like...

 

Thu, 07 Feb 2013 14:14:00 GMT

Thu, 07 Feb 2013 18:58:00 GMT

Tues, 05 Feb 2013 12:45:00 GMT

Wed, 06 Feb 2013 12:22:00 GMT

 

Wed, 06 Feb 2013 15:52:00 GMT

 

But see, it's ordering them by day, not full date, day, and time together. Can I remove this sorting?

 

Thanks

 

Developer
Posts: 148
Registered: ‎10-30-2010
My Device: Bold 9930
My Carrier: Verizon

Re: Ordering ListView items by date

Sorry to bump. Does anyone have a solution for this?

Contributor
Posts: 22
Registered: ‎01-05-2013
My Device: Dev Alpha
My Carrier: Bell

Re: Ordering ListView items by date

You can convert the date string from the RSS feed to a QDateTime object, and then convert it to seconds using toTime_t()

 

I use that in one of my apps, and it looks something like this:

 

QString creationDate = values["creationDate"].toString();
creationDate.resize(creationDate.size() - 6); // removes timezone data from my string. You may need to do the same
QDateTime takenTime = QDateTime::fromString(creationDate, "yyyy-MM-ddThh:mm:ss");
values["creationDate"] = takenTime.toTime_t();

As yo can see, I replaced the original date value with the new value in seconds, as I had no need for the original, but you could insert the converted seconds, use that to sort ascending or decending, and keep the original if you want to display the date to the users.

Contributor
Posts: 22
Registered: ‎01-05-2013
My Device: Dev Alpha
My Carrier: Bell

Re: Ordering ListView items by date

To clarify a bit, this is done when you're inserting data into the datamodel. 'values' in my case is the map that is being inserted into a groupdatamodel