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
AlexeyPanov
Posts: 22
Registered: ‎04-18-2014
My Device: z10

How to get CustomListItem in ListView ?

   ListView {
            id: music_list
            objectName: "music_list"
            layout: StackListLayout {
                headerMode: ListHeaderMode.Sticky
            }

            listItemComponents: [
                ListItemComponent {

                    type: "item"
                    id: songcomponent

                    SongItem {
                        objectName: "songitem"
                        id: audioitem
                        duration: ListItemData.duration
                    }
                    
                }
            ] // listItemComponents

            onTriggered: {
                music_list.clearSelection();
                select(indexPath);
                var songItem = dataModel.data(indexPath);

 How can i get some data of SongItem in that list by Click On it, for example - duration . I would like to change Label in selected item of ListView ? 

Please use plain text.
Administrator
MSohm
Posts: 14,554
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: How to get CustomListItem in ListView ?

[ Edited ]

It depends on your DataModel.  But you could use songItem.Whatever to get data from songItem (after you call to var songItem = dataModel.data(indexPath).  

 

Access the data in the same way as you do in your SongItem CustomListItem's fields.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
AlexeyPanov
Posts: 22
Registered: ‎04-18-2014
My Device: z10

Re: How to get CustomListItem in ListView ?

[ Edited ]

That is works.Thanks.

 

SongItem has Label components ,so how could i update Label components in my SongItem component which was selected ? So what i want, 

1) press on any item (SongItem),

2) change(Labels,Images ,etc ) or show anything in this item (SongItem)

 

I think, i need get a reference of this item first, but not sure how to.

 

suppose i want to show indicator by pressed on a item(SongItem component ) in a ListView, SongItem component has property alias "loading"  ,  

 

piece of SongItem component (qml)

 

import bb.cascades 1.2

CustomListItem {
    dividerVisible: true
    highlightAppearance: HighlightAppearance.Full
    id: item

    property int duration: 0
    property alias loading: indicator.running

    Container {
        id: contentContainer
        topPadding: 5
        horizontalAlignment: HorizontalAlignment.Fill

        Container {
            layout: AbsoluteLayout {
                //orientation: LayoutOrientation.LeftToRight
            }
            verticalAlignment: VerticalAlignment.Fill
            horizontalAlignment: HorizontalAlignment.Fill
             
            Label {
                id: songName
                text: ListItemData.title
                verticalAlignment: VerticalAlignment.Bottom
                horizontalAlignment: HorizontalAlignment.Left
                textStyle.base: SystemDefaults.TextStyles.TitleText
                accessibilityMode: A11yMode.Collapsed
                textFit.maxFontSizeValue: 8.0
            }
ActivityIndicator {
                id: indicator
                horizontalAlignment: HorizontalAlignment.Center
                verticalAlignment: VerticalAlignment.Center
                minWidth: 50

                // set initial visibility to true
                running: false
                visible: true
            }
..
..
..
}
Please use plain text.
Developer
simon_hain
Posts: 16,134
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to get CustomListItem in ListView ?

you can retrieve the item from the dataModel using the indexPath.

Maybe this helps:
http://supportforums.blackberry.com/t5/Native-Development-Knowledge/How-to-access-qml-properties-fro...
----------------------------------------------------------
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
Please use plain text.
Developer
AlexeyPanov
Posts: 22
Registered: ‎04-18-2014
My Device: z10

Re: How to get CustomListItem in ListView ?

[ Edited ]

so i have read and i 've tried that:

 

   ListView {
            id: music_list
            objectName: "music_list"
            layout: StackListLayout {
                headerMode: ListHeaderMode.Sticky
            }

            listItemComponents: [
                // The stamp Item
                ListItemComponent {

                    type: "item"
                    id: songcomponent

                    SongItem {
                        id: audioitem
                        duration: ListItemData.duration
                    }
                    
                }
            ] // listItemComponents

            onTriggered: {
                music_list.clearSelection();
                select(indexPath);
                var songItem = dataModel.data(indexPath);
                console.log("song item " + songcomponent.ListItem.view);// doesnt work,error

get error:

 

Error: Accessing ListItem.view on a node that is not the root node in a list item visual. Try prefixing with the id of the item visual root node.

Please use plain text.
Developer
simon_hain
Posts: 16,134
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to get CustomListItem in ListView ?

see the kb article i linked to
----------------------------------------------------------
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
Please use plain text.
Developer
AlexeyPanov
Posts: 22
Registered: ‎04-18-2014
My Device: z10

Re: How to get CustomListItem in ListView ?

Could you explain to me?
Please use plain text.
Developer
simon_hain
Posts: 16,134
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to get CustomListItem in ListView ?


AlexeyPanov wrote:
Could you explain to me?

i wrote the KB article to do that. If something is unclear there i should modify if accordingly, maybe you could explain what exactly you don't understand?

----------------------------------------------------------
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
Please use plain text.
Developer
AlexeyPanov
Posts: 22
Registered: ‎04-18-2014
My Device: z10

Re: How to get CustomListItem in ListView ?

[ Edited ]

ok i try,

So, i have a ListView with items, every item represents by SongItem (QML component), which has Labels,ProgressIndicator components. So i would like to change any Labels or other component by Touch on it in the ListView.

 

i suppose , i need get a reference to instance of touched item (SongItem), but dont know how.


i hope u understand me.

Please use plain text.
Developer
simon_hain
Posts: 16,134
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to get CustomListItem in ListView ?

the touched item would be just ListItemData
ListItemData.title = "new title" would set the title property.
----------------------------------------------------------
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
Please use plain text.