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
Mitch99
Posts: 102
Registered: ‎05-09-2013
My Device: BB10 Z10
My Carrier: Virgin
Accepted Solution

setting parameters of custom List Item

Hi all,

 

I'm trying to pass parameters to custom List Item, which I defined as such:

 

listItemComponents: [
    ListItemComponent {
        type: "item"
        ComponentListItem {
            li_mainTitle: 	"Test Type"		// <-- WORKS
            li_textReading: lis.textReading		// <-- DOESN'T WORK
        } 
    }
]

 ComponentListItem is defined in a separate file, ComponentListItem.qml. Now - I can set its parameters outside of the QML file if I set the parameters to constants (strings in this case), but setting parameters to variables doesn't work. Does anyone have any idea how to acomplish this?

Please use plain text.
Developer
matizeitune
Posts: 366
Registered: ‎07-15-2013
My Device: blackberry Z10
My Carrier: Personal

Re: setting parameters of custom List Item

Page{
property string mainTitle;
property string textReading;

listItemComponents: [
    ListItemComponent {
        type: "item"


onCreationCompleted:{
mainTitle="TestType";
textReading=lis.textReading
}
        ComponentListItem {
            Label{
 	text:mainTitle
}		
Label{
            text: textReading	
}	
        } 
    }
]


}

 

If you find this information useful please click like --->
@mezeitune on twitter
Please use plain text.
Developer
matizeitune
Posts: 366
Registered: ‎07-15-2013
My Device: blackberry Z10
My Carrier: Personal

Re: setting parameters of custom List Item

[ Edited ]
textReading = lis.textReading;

 correcion that line

If you find this information useful please click like --->
@mezeitune on twitter
Please use plain text.
Trusted Contributor
Mitch99
Posts: 102
Registered: ‎05-09-2013
My Device: BB10 Z10
My Carrier: Virgin

Re: setting parameters of custom List Item

Thanks, however, I tried that... ListItemComponent doesn't have onCreationCompleted signal.

Please use plain text.
Developer
matizeitune
Posts: 366
Registered: ‎07-15-2013
My Device: blackberry Z10
My Carrier: Personal

Re: setting parameters of custom List Item

but onCretionCompleted, so you have to create outside the listview
  something like

 

Page{
property string mainTitle;
property string textReading;
ListView{
listItemComponents: [
    ListItemComponent {
        type: "item"



        ComponentListItem {
            Label{
 	text:mainTitle
}		
Label{
            text: textReading	
}	
        } 
    }
]

}

onCreationCompleted:{
mainTitle="TestType";
textReading=lis.textReading;
}
}

 

 

I hope that can you serve

If you find this information useful please click like --->
@mezeitune on twitter
Please use plain text.
Trusted Contributor
Mitch99
Posts: 102
Registered: ‎05-09-2013
My Device: BB10 Z10
My Carrier: Virgin

Re: setting parameters of custom List Item

Sorry, but again, that doesn't work. All the visual components are defined in the ComponentListItem.qml file. I have no Label components, so setting parameters on them is pointless.

Please use plain text.
Developer
matizeitune
Posts: 366
Registered: ‎07-15-2013
My Device: blackberry Z10
My Carrier: Personal

Re: setting parameters of custom List Item

test with this:

Page{
property string mainTitle;
property string textReading;
ListView{
listItemComponents: [
    ListItemComponent {
        type: "item"

ComponentListItem{

}

 
    }
]

}

onCreationCompleted:{
mainTitle="TestType";
textReading=lis.textReading;
}
}

 

If you find this information useful please click like --->
@mezeitune on twitter
Please use plain text.
Trusted Contributor
Mitch99
Posts: 102
Registered: ‎05-09-2013
My Device: BB10 Z10
My Carrier: Virgin

Re: setting parameters of custom List Item

I don't get it... I'm trying to set variables IN ComponentListItem... Which is not happening here.... all that's being set are properties from Page

 

Let's reboot. Here's a simplified ComponentListItem.QML:

import bb.cascades 1.0

    
Container {

    Label {
        id: l1
    }

    Label {
        id: l2
    }
}

 If I'm using it in this way:

Page{
	ListView{
		listItemComponents: [
    			ListItemComponent {
        			type: "item"
				ComponentListItem{
				}
    			}
		]
	}
}

 How do I set l1.text and l2 text from within Page?

 

 

 

Please use plain text.
Developer
pyth
Posts: 479
Registered: ‎01-19-2011
My Device: My Trusty Red Plane
My Carrier: Outer Space

Re: setting parameters of custom List Item

del

see here: https://developer.blackberry.com/native/documentation/cascades/ui/lists/list_view.html

 


in your ListItemComponent, you always have a refernce to ListItemData, which is the data of the current list item

 

So in your case it would be just

    Container {
        layout: StackLayout {
            orientation: LayoutOrientation.LeftToRight
        }
        Label {
            text: ListItemData.textLabel
            layoutProperties: StackLayoutProperties {
                spaceQuota: 1.0
            }
        }
        
        Label {
            text: ListItemData.detailTextLabel
        }
    }

 (depending on your data model. I used a GroupDataModel here, which had two keys, textLabel and detailTextLabel)

 

if you want to set the labels directly ffrom your Page.qml, just create properties

    Container {

        property variant textLabel
        property variant detailTextLabel

        layout: StackLayout {
            orientation: LayoutOrientation.LeftToRight
        }
        Label {
            text: textLabel
            layoutProperties: StackLayoutProperties {
                spaceQuota: 1.0
            }
        }
        
        Label {
            text: detailTextLabel
        }
    }

 

 

-----------------------------------------------------------------------
I'm a bird from outer space. But I'm not flappy o.o
Please use plain text.
Trusted Contributor
Mitch99
Posts: 102
Registered: ‎05-09-2013
My Device: BB10 Z10
My Carrier: Virgin

Re: setting parameters of custom List Item

Thanks for the answer. Not quite what I wanted... I need to set the parameters from within the Page itself. Properties are fine when set explicitly, like this:

 

                        listItemComponents: [
                            ListItemComponent {
                                type: "item"
                                ComponentLI {
                                    backgroundSource: "asset:///images/backgnd.png"
                                }
                            }
						]

 However, for some reason it won't take a variable:

 

Page {
    id: prl
    property variant backgroundSource: "asset:///images/backgnd.png"
...

                   listItemComponents: [
                      ListItemComponent {
                          type: "item"
                          ComponentLI {
                          backgroundSource: prl.backgroundSource
                        }
                     }
		]

 Any idea why this doesn't work?

Please use plain text.