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
ankursahu19
Posts: 64
Registered: ‎03-20-2013
My Device: Z10(Red Limited Edition)

how to protect the listview cell to not reuse

Hello All,
         i'm a create a model class in cpp which inherits bb::cascades::datamodel, this model using in listview as datamodel. data() of the datamodel return class (wrapped in Qvariant). this class have some property which is used in listview. i'm facing a problem when we scrolling the list those item used again when another item of the same type scrolls into the visible area.

 

So, is there any signals or workaround to not reuse cell.

any suggestions are welcome.

 

Thanks and regards
Ankur

Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: how to protect the listview cell to not reuse

Hi!
ListView reuses it's components, this can't be changed. If they're bound to dataModel fields they should be updated on reuse. Just make sure that all state changes of the controls are made via the model, not directly.

If using C++ ListItemProvider, the fields should be updated in updateItem() method.

If item reuse isn't needed, a simple Container with ScrollView can be used instead. It can be filled manually with items from the model. But if there are many items to create, this can be slow, especially initial population of the container.


Andrey Fidrya, @zmeyc on twitter
Developer
ankursahu19
Posts: 64
Registered: ‎03-20-2013
My Device: Z10(Red Limited Edition)

Re: how to protect the listview cell to not reuse

Before implementing this ,I used the container but now i need some customization over the cell. Thats why i have to use ListView.

 

Can you please elaborate how would i use listitemprovider and also how to associate with model class and

 

Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: how to protect the listview cell to not reuse

There's a good explanation by Peter here on the problem...

 

http://supportforums.blackberry.com/t5/Native-Development/LstItemComponent-doesn-t-track-the-model-c...

 

My suggestion is to write this 'reuse' info back to your model or create your own ListView custom control.


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
ankursahu19
Posts: 64
Registered: ‎03-20-2013
My Device: Z10(Red Limited Edition)

Re: how to protect the listview cell to not reuse

[ Edited ]

ListItemProvider uses VisualNode objects as items in a ListView.

but here i'm using cpp class to populate listview item.

so how i can use listitemprovider for escaping from reuse of listview.

 

or correct me if i am wrong.

Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: how to protect the listview cell to not reuse

I'm struggling to understand your last post, whether you use C++ or QML makes no difference.

 

If you read the link I gave you you would see that ListItem.initialised let's you know if the item has been recycled or not, with that you should be able to write code that will either update or not update the visual componant as required dependant on that property.


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
ankursahu19
Posts: 64
Registered: ‎03-20-2013
My Device: Z10(Red Limited Edition)

Re: how to protect the listview cell to not reuse

Actually, as i understand ,the ListItemProvider providing VisualNode objects in listview. and A visual node in the scene graph.

 

but in my scenario i'v a own model class in cpp which inherits bb::cascades::datamodel, this model used in listview as datamodel. data() function of the model class return class (wrapped in Qvariant). So i'm confuse now, how i can use ListitemProvider class to update listview cell. or is another way to update cell after recycle in listview.

 

Developer
Paratheo
Posts: 134
Registered: ‎04-25-2009
My Device: Z30

Re: how to protect the listview cell to not reuse

Post your list code so i can help you fix it. I've run into this kind of issue many times before and its easy to fix. Usually you just have to make sure that you reference directly to the datamodel and not on bindings.