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
Trusted Contributor
Brennan12325
Posts: 204
Registered: ‎05-15-2012
My Device: None
My Carrier: Telus

Append to DataModel and have changes reflected in ListView

If I've set up a DataModel with 10 items, for example, then a slot executes with the intent of adding 10 more items to this ListView, how would I got about doing this in an educated way?

 

I'm under the impression a ListView can handle more than one DataModel? I'd hate to do that, since then I'd need to maintain a list of DataModels, due to no limit to the amount of times the SLOT could be called.

 

What is the correct way (if it's even feasible) to simply add entries to a DataModel, then update the ListView to reflect those changes, preferably without reparsing the components of the DataModel that are already displayed. The DataModel has and itemAdded SIGNAL which makes me think this is probably a feasible use case, however, I'm expecting to see something like an "update" in the ListView object and I'm not finding it.

 

- Brennan

----------------------
Check out my app, Alien Flow for reddit

And of course, like my post if you found it helpful or informative!
Please use plain text.
Trusted Contributor
Brennan12325
Posts: 204
Registered: ‎05-15-2012
My Device: None
My Carrier: Telus

Re: Append to DataModel and have changes reflected in ListView

The best I can do right now is clearing the data model, adding the first 10 items + the new 10 items to the data model, calling list->resetDataModel(), then list->setDataModel(&model), which will re-render the list will all of the new items.

 

I suppose to make it 'feel' more correct I could also call scrollToItem on the list to go to the new data.

 

This is definitely a less than ideal solution to simply adding to the data model and having the ListView handle it gracefully. This is more computationally expensive then I'd like.

----------------------
Check out my app, Alien Flow for reddit

And of course, like my post if you found it helpful or informative!
Please use plain text.
BlackBerry Development Advisor (Retired)
smacmartin
Posts: 499
Registered: ‎05-07-2012
My Device: developer
My Carrier: developer

Re: Append to DataModel and have changes reflected in ListView

This does not sound like the correct approach to me.

 

Please read knowledge base articles

http://supportforums.blackberry.com/t5/Cascades-Development-Knowledge/Using-your-own-DataModel/ta-p/...

and then

http://supportforums.blackberry.com/t5/Cascades-Development-Knowledge/Using-a-Custom-DataModel-to-Fi...

 

and let us know if you can figure it out from there or have more questions.

These articles don't directly answer your question but should help.

 

Stuart

Please use plain text.