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
Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10
My Carrier: Fido

Multiple DataModels in one ListView??

[ Edited ]

Hi,

 

(Please note that I am NOT using QML)

 

I would like to create a ListView with varying types of list items. Is there any way I can use more than one

QVariantListDataModel on a listview? I need different list view cells to show different data and probably be of different sizes. Is this possible?

 

Thanks!

Developer
Posts: 1,008
Registered: ‎12-12-2010
My Device: Passport (Red Limited Edition)
My Carrier: Mobile Vikings

Re: Multiple DataModels in one ListView??

One ListView can only display a single DataModel at a given time. However you can easily swap DataModels, if that is what you're after?

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10
My Carrier: Fido

Re: Multiple DataModels in one ListView??

[ Edited ]

Thanks for the reply!

 

No I don't think swapping is what I'm after, I would like a ListView where each item can potentially contain different types of content, different backgrounds and can be of different heights.

 

I am selecting from 4 or 5 different SQL tables, which are completely different but share one common field (IDNum), I would like to sort these by IDNum and have a ListView display them, where items of type A might show an image and a label, items of type B may show only 3 labels, items of type C may show two images and have a different background color. This is just an example.

 

How can I achieve this?

 

Thanks!

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Multiple DataModels in one ListView??

Each of the data models supports items of different types too. Just look into the itemType() method. The return value of that matches up with the defined type of the list item components, which encapsulate the visual differences you want.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10
My Carrier: Fido

Re: Multiple DataModels in one ListView??

[ Edited ]

Really?

 

Would you happen to have a link to an example of this? Or know of any sample apps that do this?

 

Right now I am doing the following:

 

QVariantList

list = reply.result().toList();

 

QVariantMap map = QVariantMap();

 

foreach (QVariant entry, list)

{

   QVariantMap m = entry.toMap();

 

   map["title"] = m["AirSegmentNumber"].toString();

   map["image"] = QString("assets/icons/suitcase.png");

   map["pnrid"] = m["PnrID"].toString();

 

   myTripModel<< map;

}

myListView->setDataModel(&myTripModel);

 

Where myTripModel is of type bb::cascades::QVariantListDataModel. How would I go about adding items of different types??

Developer
Posts: 1,008
Registered: ‎12-12-2010
My Device: Passport (Red Limited Edition)
My Carrier: Mobile Vikings

Re: Multiple DataModels in one ListView??

Sure the List View documents such an example. In your DataModel you need to implement the following method:

 

Q_INVOKABLE QString itemType (const QVariantList &indexPath)

 Based on this method the proper ListItemComponent you define gets selected.

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10
My Carrier: Fido

Re: Multiple DataModels in one ListView??

ListItemComponents is only available in QML?? That's what it says in the documentation, I'm trying to avoid that.

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Multiple DataModels in one ListView??

That's true, and why I didn't capitalize the term. I just mean the C++ equivalent, which I don't use since I do only QML. I think it's ListItemProvider? The docs do cover all this if you read through them all. Sorry I can't be more specific.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!