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
Regular Contributor
Posts: 60
Registered: ‎12-19-2012
My Device: BB10 Alpha B
My Carrier: SFR
Accepted Solution

Switch ListItemComponent at runtime

Hi !

 

I have a ListView displaying some favorites to my user. I want to have two different representations of these favorites the user can choose between with a button. So I think I should just change the listItemComponents property of my ListView at run time. But so far, as I haven't found a way to store a ListItemComponent on a variable, I don't see how I can achieve this. I would like to avoid to have two ListView, one shown and one hidden.

 

Thanks.

Regular Contributor
Posts: 60
Registered: ‎12-19-2012
My Device: BB10 Alpha B
My Carrier: SFR

Re: Switch ListItemComponent at runtime

Any ideas ?

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

Re: Switch ListItemComponent at runtime

You could reuse the same ListView, but with two different ListItemComponents (one for each view). One ListItemComponent handles the items of itemType "view1", the other of "view2".

 

When a user selects another view, just change the itemTypes returned by the DataModel.

-------------------------------------------
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!
Regular Contributor
Posts: 60
Registered: ‎12-19-2012
My Device: BB10 Alpha B
My Carrier: SFR

Re: Switch ListItemComponent at runtime

Good idea. My model comes from C++ and is a QLIstaDataModel of custom QObject. Can I change the itemType from QML ?

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

Re: Switch ListItemComponent at runtime

I don't see how, it would be better to make a method in your DataModel that is invokable from QML (mark it with Q_INVOKABLE). That method then can just toggle between the views and signal that the datamodel has new data for the listview.

-------------------------------------------
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!