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
esam_tec
Posts: 85
Registered: ‎06-22-2013
My Device: N/A
Accepted Solution

Get the title or the contents of the a selected item from list view ?

Hello guys, i've made a list view and i need to get the content of the selected item (Ontriggerd item)  

 

onTriggered: {
lable.text  = ??
navigationPane.push(bPage);
}

 

thanks

Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Get the title or the contents of the a selected item from list view ?

The onTriggered handler gets an "indexPath" argument passed in. You can hand that to the datamodel's data() function and it will return the item at that location. You can then pull the required property off the item, whatever it may be, something like this:

label.text = myDataModel.data(indexPath).someProperty

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
esam_tec
Posts: 85
Registered: ‎06-22-2013
My Device: N/A

Re: Get the title or the contents of the a selected item from list view ?

thanks, i can't find property to get the title  

lable.text = dataModel.data(indexPath);

Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Get the title or the contents of the a selected item from list view ?

The property will depend on the nature of your original data model. Are you using an XML source? What do you use in your StandardListItem (or custom component) to get the title or other properties? It's no different than what you do there except you won't be using ListItemData to get to the data model element.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
esam_tec
Posts: 85
Registered: ‎06-22-2013
My Device: N/A

Re: Get the title or the contents of the a selected item from list view ?

listItemComponents: [
ListItemComponent {
type: "item"
StandardListItem {
title: qsTr("%1 %2").arg(ListItemData.productName).arg(ListItemData.productPrice)
}

}
]
Developer
DrShavargo
Posts: 133
Registered: ‎05-10-2013
My Device: Blackberry Z10

Re: Get the title or the contents of the a selected item from list view ?

[ Edited ]

dataModel.data(indexPath) will return a QVariant. To call ".someProperty", you'll need to know the type of the object (int, string, etc.) and call the appropriate function (toInt, toString, etc.). For example, if your QVariant holds string items:

 

lable.text = dataModel.data(indexPath).toString();

 

As a side example, if it holds a StandardListItem object:

 

label.text = dataModel.data(indexPath).title();

----------------------------------------
Remember to mark the thread as solved at the post that solved your problem, and if you like a post, like it!
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Get the title or the contents of the a selected item from list view ?

esam_tec, when you say you want the "title", do you mean you want to retrieve the complete string that you show there, built with qsTr("%1 %2").arg(...) ?

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
esam_tec
Posts: 85
Registered: ‎06-22-2013
My Device: N/A

Re: Get the title or the contents of the a selected item from list view ?

Thanks peter9477, problem solved :smileyhappy:
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Get the title or the contents of the a selected item from list view ?

So calling title() worked? It will help others who are searching for answers later if you can clarify. Thanks! :smileyhappy:

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
esam_tec
Posts: 85
Registered: ‎06-22-2013
My Device: N/A

Re: Get the title or the contents of the a selected item from list view ?

the that stored in the dataModel of type class , so i have used
title: qsTr("%1 ").arg(ListItemData.productName) to load to the list

and i have used this line to get the content back
lable.text = dataModel.data(indexPath).productName.toString();

i hope this can help any one .