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
marioi
Posts: 43
Registered: ‎07-23-2013
My Device: Z10
Accepted Solution

Pass a defined variable value from Picker to Listview

[ Edited ]

This has probably been covered numerous times on the forum, but I'm going crazy with searches and trying to get it right with my code.

 

All I'm trying to do is to expose the variable rssmobileEnabled defined in the PICKER, so that I can pass and test it in the IF statement of my LISTVIEW's onSelectedValueChanged, as per the code below.

 

I have made the variable in BOLD below to indicate this. This has to be a simple solution, afterall how can it be difficult to just define a global variable...

 

PICKER code:

 

 Picker {
    id: picker
    title: "Select Feed"
    dataModel: XmlDataModel {
     source: "models/blackberry.xml"
    }

      pickerItemComponents: [
          PickerItemComponent {
                type: "rsslink"
                content: Container {
                layout: DockLayout {
                }
                     Label {
                         multiline: false
                         text: pickerItemData.text
                         textStyle {
                              base: SystemDefaults.TextStyles.SubtitleText
                         }
                      }
                  }
             }
        ]

   onSelectedValueChanged: {
       var rsslinktext = (dataModel.data([ 0, picker.selectedIndex(0) ]).text);
       var rsslink = (dataModel.data([ 0, picker.selectedIndex(0) ]).rssSource);
       var rsslinkquery = (dataModel.data([ 0, picker.selectedIndex(0) ]).rssQuery);
       var rssmobileEnabled = (dataModel.data([ 0, picker.selectedIndex(0)]).mobileEnabled);

        //Load the selected feed
        dataSource.load();
   }
} // Picker

 

LISTVIEW code:

 

            ListView {
                id: myListView

                // Associate the list view with the data model that's defined in the
                // attachedObjects list
                dataModel: dataModellist
                layout: StackListLayout {}
                listItemComponents: [
                    ListItemComponent {
                        id: header
                        type: "header" //"item"

                        //custom components used instead of standardlistitem
                        Container {
                            Label {
                                id: emptytextheader
                                text: ""
                            }
                        }
                    },
                    ListItemComponent {
                        id: item
                        type: "item" //"description"

                        Container {
                            layout: DockLayout {}
                            //custom components used instead of standardlistitem

                            Container {
                                id: itemdetails
                                Label {
                                    id: title
                                    text: ListItemData.title
                                    //textStyle.fontWeight: FontWeight.Bold
                                    multiline: true
                                    textStyle.color: Color.Cyan
                                }
                                Label {
                                    id: pubdate
                                    text: ListItemData.pubDate
                                    textStyle.color: Color.create("#ff00c200")
                                    textStyle.fontSize: FontSize.XSmall
                                }
                                Label {
                                    id: description
                                    text: ListItemData.description
                                    textStyle.fontSize: FontSize.Small
                                    multiline: true
                                    textStyle.color: Color.Yellow
                                    maxHeight: 130.0
                                }
                            }
                        }
                    }
                ]

                onTriggered: {
                    var feedItem = dataModel.data(indexPath);
                    var page = detailsPage.createObject();
                    
                    if (rssmobileEnabled == "y")
                    	{
                            .....
                        }
                }
            }

 

 

Developer
Zmey
Posts: 1,515
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Pass a defined variable value from Picker to Listview

Hi,

 

'var rssMobileEnabled' declares a local variable, so it's not accessible in onTriggered.

 

Declare it as property instead:

TopLevelItem
{
   property bool rssMobileEnabled
   (or 'property string' if it's a character)

reference it without 'var' prefix:

 

rssMobileEnabled = ...

 

You can also declare the property on any other element (not neccessarily top-level) and reference it via id:

 

elementId.rssMobileEnabled

 


Andrey Fidrya, @zmeyc on twitter
Developer
marioi
Posts: 43
Registered: ‎07-23-2013
My Device: Z10

Re: Pass a defined variable value from Picker to Listview

Zmey, you are king!! It worked and even better, has made me understand the concept even better about declaring a custom property which can be referenced elsewhere.

 

Thank you!!