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

New Developer
Posts: 4
Registered: ‎02-05-2014
My Device: z10
My Carrier: z10
Accepted Solution

How to select a listItem from outside the list!

Hello guys! I'm developing an app about meetings, and I'm facing a bit of a problem.The thing is: in the app I need a list to respond to a music. Explaining better: I want the list to automatically change selection when the music reaches a predetermined point. Like when its stars, the first item should be selected, then when it gets to 10 seconds, It shoud jump to the next one, and on so. To do the checks on the position of the music, i use OnPositionChanged. This is the bit of code:

onPositionChanged: {
> > console.log("BBBBBBBBBB")
> >
> > var i = myModel.data(myModel.find(["topic1","1"]))
> > if (mediaPlayer.position >= i.startTime{
> > listView.select(i,true)
> >
> > }

In this case, the list takes the data from the dataModel, and the first one has the title Topic1 and a property called startTime wich in this case i set to 1. If i run the app, when the music stars and the first signal of the position changed is sent, the console displays "BBBBBBBBBBB", then the if check is effective, cause the console displays "AAAAAAAAAAAAAAA", but nothing happens on the list, and the item is does not get selected. I tought it could be maybe an error in the "var i = myModel.data(myModel.find(["topic1","1"]))" part, but then I called console.log("i.startTime") and the console.displays the 1... so the only thing left it's the listView.select part.. Does anybody knows how do I call an item selection from outside the List View component?

Posts: 16,999
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to select a listItem from outside the list!

welcome to the support forums.
i suggest you re-read the ListView/DataModel API carefully.
to call select you need the index path.
data() returns the list item associated with the index path.
find() returns the index path, which you need to call select.

use a var to store the indexPath, then use that on data() and on select().

and, if i may offer an unrelated suggestion, use 'i' only for counter variables, use speaking names for others, for example 'indexPath'.
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
Posts: 4
Registered: ‎02-05-2014
My Device: z10
My Carrier: z10

Re: How to select a listItem from outside the list!

I think that will solve my problems! And thanks for the adivce about the variables name, will follow it. My simulator is not cooperating but in the near future I'll test it and if it works will mark as solution! Thanks a lot!