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

Access view children of a ListView

Hi !

 

I have a ListView and would like to inject some elements in the container of the row, based upon very specific circumstances. Hence, I have to do this from c++. From a ListView object, I am using the children() method to get a ListItemComponent, a class only available in QML according to the Documentation. But how can I acess a child view of a ListView in C++ ?

 

Thanks

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Access view children of a ListView

[ Edited ]

I don't know how to access the data from C++ if ListView was created using ListItemComponents.

 

But you can configure ListView to use a model (one of DataModel subclasses) and ListItemProvider to create the items. Then access the data using the model:

 

listView.model().data(indexPath)

listView.model().childCount()

 

When model is updated listView will call ListItemProvider's updateItem() where you can make the changes to visuals.

 

Keeping a pointer to visual item to change it directly is unsafe because ListView owns it and can reuse it for other row at any moment.


Andrey Fidrya, @zmeyc on twitter
Regular Contributor
Posts: 60
Registered: ‎12-19-2012
My Device: BB10 Alpha B
My Carrier: SFR

Re: Access view children of a ListView

Yes but this will give me access to the data of the item, not the view itself.

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Access view children of a ListView

Access the view in ListItemProvider's updateItem().

Modify the data to trigger updates.


Andrey Fidrya, @zmeyc on twitter
Contributor
Posts: 10
Registered: ‎10-29-2012
My Device: Blackberry Curve 8520
My Carrier: Idea

Re: Access view children of a ListView

has anybody done this yet?
Developer
Posts: 71
Registered: ‎09-19-2012
My Device: Z10 very soon
My Carrier: Play

Re: Access view children of a ListView

Please provide more details about what you want to do. An example with cpp and qml will help to understand your goals.. Many devs complicate simple things.

 

You can use control delegates to change ui of listview items.

 

Developer
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: Access view children of a ListView

Because the listitems are recycled, and the fact that they are based on the underlying data, I would suggest that you have whatever dynamic data you are wanting to add already in the item just set to visible=false.

Then you can update the underlying data and can make the content show based on whatever criteria needs to be met for that section to show. The listview and components structure was not designed to update a single cell and its data since the data changes in a single component as scrolling happens.
Like all of my posts
Contributor
Posts: 10
Registered: ‎10-29-2012
My Device: Blackberry Curve 8520
My Carrier: Idea

Re: Access view children of a ListView

Actually I've to show a Label inside listView items. Certain alphabets of the Label will be colored based on some logic. How to get certain alphabets of the Label colored deserves another post. But for this thread, whenever a row is created or recycled I want to run the logic to present the Label with text colored.