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: 101
Registered: ‎01-06-2014
My Device: Q10
My Carrier: EE

ListView not working - won't allow me to navigate to different pages

I have list view within my main page but it doesn't navigate to other pages when I tap the items:

import bb.cascades 1.2
 
NavigationPane {
Page {
    titleBar: TitleBar {
        title: "Welcome"
    }
    Container {
        //Todo: fill me with QML
        ListView {
             id: mainList
             dataModel: XmlDataModel {source: "models/main.xml"}
             listItemComponents: [
                 ListItemComponent {
                     type: "item"
                     StandardListItem {
                         title: ListItemData.title
                         description: ListItemData.text
                         imageSource: ListItemData.image
                         imageSpaceReserved: true
                        }
                    }
                ]
                onTriggered: {
                    // When an item is selected, we push the recipe Page in the chosenItem file attribute.
                    var chosenItem = dataModel.data(indexPath);
                    
                    // Set the correct file source on the ComponentDefinition, create the Page, and set its title.
                    chosenPage.source = chosenItem.file;
                    var page = chosenPage.createObject();
                    page.title = chosenItem.title;
 
                    // Push the new Page.
                    nav.push(page);
                }
            }
        }
    }
}
 

 

XML

<root>
    <item title="Choose a station"	image="asset:///images/roundel.png" 		file="station_chooser.qml"/>
    <item title="Social"	text="Don't be anti-social"		 	image="asset:///images/social.png"			file="social.qml"/>
    <item title="About"       		image="asset:///images/ic_info.png"			file="about.qml"/>
</root>

 

Developer
Posts: 1,046
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: ListView not working - won't allow me to navigate to different pages

I am going to assume that chosenItem.file returns the correct value. Everything else looks pretty good, except...

 

...this line doesn't look right to me:

 

chosenPage.source = chosenItem.file;

I don't see anywhere that you define chosenPage. Did you forget to attach the ComponentDefinition to the Page?

 

I would almost be willing to bet that if you step though onTriggered() with the debugger it will get to that line then choke and fail to execute any of the following lines.



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 101
Registered: ‎01-06-2014
My Device: Q10
My Carrier: EE

Re: ListView not working - won't allow me to navigate to different pages

I believe that I forget but I don't know what to actually put there as regards to this.

Developer
Posts: 1,046
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: ListView not working - won't allow me to navigate to different pages

[ Edited ]

Ok, well I haven't ever used ComponentDefinition quite the way you are, but I think this might work...

 

import bb.cascades 1.2
 
NavigationPane {
Page {
    titleBar: TitleBar {
        title: "Welcome"
    }
    Container {
        //Todo: fill me with QML
        ListView {
             id: mainList
             dataModel: XmlDataModel {source: "models/main.xml"}
             listItemComponents: [
                 ListItemComponent {
                     type: "item"
                     StandardListItem {
                         title: ListItemData.title
                         description: ListItemData.text
                         imageSource: ListItemData.image
                         imageSpaceReserved: true
                        }
                    }
                ]
                onTriggered: {
                    // When an item is selected, we push the recipe Page in the chosenItem file attribute.
                    var chosenItem = dataModel.data(indexPath);
                    
                    // Set the correct file source on the ComponentDefinition, create the Page, and set its title.
                    chosenPage.source = chosenItem.file;
                    var page = chosenPage.createObject();
                    page.title = chosenItem.title;
 
                    // Push the new Page.
                    nav.push(page);
                }
            }
        }
    }
    attachedObjects: [
        ComponentDefinition {
            id: chosenPage 
        }
    ]
}

I have always defined the ComponentDefinition completely rather than loading the definition via source so I'm not certain this will work, but it should be a starting point anyway.



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 101
Registered: ‎01-06-2014
My Device: Q10
My Carrier: EE

Re: ListView not working - won't allow me to navigate to different pages

Unfortunately this doesn't work as I get this error:

 

asset:///main.qml:60: Error: Cannot assign to non-existent property "title"

 So how can I define the ComponentDefinition completely rather than loading the definition via source?

Developer
Posts: 101
Registered: ‎01-06-2014
My Device: Q10
My Carrier: EE

Re: ListView not working - won't allow me to navigate to different pages

Anyone?