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
Posts: 366
Registered: ‎07-15-2013
My Device: blackberry Z10
My Carrier: Personal
Accepted Solution

Random Botton

[ Edited ]

Hi all, how could I put a button to randomly select an item from the listview and display it in a label

this is the code where I want to apply
http://paste2.org/m92MN1CX

thanks

If you find this information useful please click like --->
@mezeitune on twitter
Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Random Botton

[ Edited ]

use a random int and get the element it indicates from the data source.

https://developer.nokia.com/Community/Wiki/Generating_random-value_integers_in_Qt

----------------------------------------------------------
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
Developer
Posts: 133
Registered: ‎05-10-2013
My Device: Blackberry Z10
My Carrier: -

Re: Random Botton

[ Edited ]

 

Button{
  onClicked:{
int size = groupDataModel.size() rand = Math.ceil(Math.random()*size) //can also use randInt(0, size); listview.triggered(rand); } }

 

----------------------------------------
Remember to mark the thread as solved at the post that solved your problem, and if you like a post, like it!
Developer
Posts: 366
Registered: ‎07-15-2013
My Device: blackberry Z10
My Carrier: Personal

Re: Random Botton

Thanks for responding, but I have some problems, do not check syntax errors or anything, but when I pulled the button nothing happens, I analyzed the code and it seems perfect, the problem is mine, Where would have to put the code that you gave that ?
I'm putting it here:

 

Container{
layout: StackLayout {
}

Button{
text:qsTr("Random")
onClicked: {
size = groupDataModel.size();
rand = Math.ceil(Math.random()*size); //can also use randInt(0, size);
listview.triggered(rand);
}
horizontalAlignment: HorizontalAlignment.Fill
}


TextField {
hintText: qsTr("Busque su receta ")
horizontalAlignment: HorizontalAlignment.Left
input.submitKey: SubmitKey.Search

}
Button {
text:qsTr("Buscar")
onClicked: {

}
}

}


 

If you find this information useful please click like --->
@mezeitune on twitter