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
Contributor
Posts: 19
Registered: ‎07-12-2012
My Device: 9700, Playbook 16GB, and Dev Alpha
My Carrier: Starhub
Accepted Solution

TabbedPane - Sending property value when new tab is selected

[ Edited ]

Hi just for tutorial purpose, I have two tabs: Veggie and Fruit.

 

Both tabs will use the same qml file (inside is a single ListView) but of course will use different DataModel.

 

So, I set up a property for the DataModel source, and set it when the active tab changed,

 

Here's my simplified code:

 

//main.qml
TabbedPane{
    Tab{
        title: "Veggie"
        MyNextPage{}
    }
    Tab{
        title: "Fruit"
        MyNextPage{}
    }

//Looks like here's the problem onActiveTabChanged:{ var page = myComponentDefinition.createObject(); if(activeTab.title == "Veggie") page.dataModelSource = "models/veggie.xml"; else{ page.dataModelSource = "models/fruit.xml"; } } attachedObjects: [ ComponentDefinition { id: myComponentDefinition source: "MyNextPage.qml" } ] }

 

//MyNextPage.qml
Page{
    property alias dataModelSource: myListView.dataModel.source
    Content{
        ListView{
            id: myListView
            layout: ...
            dataModel: XmlDataModel{
                source: "models/veggie.xml"
            }
        }
    }
}

 

But it freezes my application. I am not sure on how this property stuff works. Any solution or alternative way to send a value to other page?

 

Thanks before

Developer
Developer
Posts: 174
Registered: ‎03-05-2009
My Device: Dev Alpha
My Carrier: -

Re: TabbedPane - Sending property value when new tab is selected

try the modified code below:

 


DarcAlpha wrote:

Hi just for tutorial purpose, I have two tabs: Veggie and Fruit.

 

Both tabs will use the same qml file (inside is a single ListView) but of course will use different DataModel.

 

So, I set up a property for the DataModel source, and set it when the active tab changed,

 

Here's my simplified code:

 

//main.qml
TabbedPane{
    Tab{
        title: "Veggie"
        MyNextPage{}
    }
    Tab{
        title: "Fruit"
        MyNextPage{}
    }

//Looks like here's the problem onActiveTabChanged:{ var page = myComponentDefinition.createObject(); if(activeTab.title == "Veggie") page.dataModel.source = "models/veggie.xml"; else{ page.dataModel.source = "models/fruit.xml"; } } attachedObjects: [ ComponentDefinition { id: myComponentDefinition source: "MyNextPage.qml" } ] }

 

//MyNextPage.qml
Page{
    property alias dataModelSource: myListView.dataModel.source
    Content{
        ListView{
            id: myListView
            layout: ...
            dataModel: XmlDataModel{
                source: "models/veggie.xml"
            }
        }
    }
}

 

But it freezes my application. I am not sure on how this property stuff works. Any solution or alternative way to send a value to other page?

 

Thanks before




Developer
Posts: 87
Registered: ‎07-23-2009
My Device: Z30
My Carrier: XL

Re: TabbedPane - Sending property value when new tab is selected

it is more simple if you don't attach the page, like this:

 

//MyNextPage.qml
Page{
    property alias dataSource: dataModel.source
    Content{
        ListView{
            id: myListView
            layout: ...
            dataModel: XmlDataModel{
                id : dataModel
                //source: "models/veggie.xml"
            }
        }
    }
}

 

and then in your tabbedpane

 

TabbedPane{
    Tab{
        title: "Veggie"
        MyNextPage{
dataSource : "models/veggie.xml";
}
    }
    Tab{
        title: "Fruit"
        MyNextPage{
    dataSource : "models/fruit.xml";
}
    }
}

 

Contributor
Posts: 19
Registered: ‎07-12-2012
My Device: 9700, Playbook 16GB, and Dev Alpha
My Carrier: Starhub

Re: TabbedPane - Sending property value when new tab is selected

[ Edited ]

@lew

Thanks for the answer. The app doesn't freeze anymore but it does not detect the dataModel source changes. I tried hakimrie solution and it works.


Sorry for the late reply and thank you for your time

Contributor
Posts: 19
Registered: ‎07-12-2012
My Device: 9700, Playbook 16GB, and Dev Alpha
My Carrier: Starhub

Re: TabbedPane - Sending property value when new tab is selected

@hakimrie
Thanks I just know that we can do this. It works!