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
urbanglowcam
Posts: 148
Registered: ‎10-30-2010
My Device: Bold 9930

Re: Trying to get segmentedControl to toggle between Containers

It worked perfectly! I wasn't thinking straight and missed some of those true/false statements you added.

 

But I think removing the () off .selectedProperty was the main thing.

 

You've helped out a lot. Thanks Kyle.

Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Trying to get segmentedControl to toggle between Containers

Just reading this now.  This is a good case where the declarative nature of QML can make it a lot simpler and easier.

 

Rather than programmatically monitor changes to the selection option in that handler, comparing the values and directly setting the visible property, you can just "bind" the visible properties of the relevant components to the relevant property with an expression.

 

In this case, you could strip the handler routine out, and then set the visible property of the TextAreas like this:

TextArea {
   id: driverBioText
   ...
   visible: segmentedDrivers.selectedOption == biography
}

TextArea {
    id: driverStatsList
    ...
    visible: segmentedDrivers.selectedOption != biography
}

The QML engine creates a binding with the properties "under the covers", so that when the property changes, a selectedOptionChanged notification signal is received and all other properties which are bound to it immediately update as required.

 

I haven't tested the above exactly as-is, so I might have overlooked something in the specifics, but the principal is sound.  (You could also use selectedValue if you prefer checking against that but the above would be better form, if it works.)


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
urbanglowcam
Posts: 148
Registered: ‎10-30-2010
My Device: Bold 9930

Re: Trying to get segmentedControl to toggle between Containers

[ Edited ]

Great thanks. I didn't know I could do that within QML. I tried following the API references and sample apps, so that's why I went the route I did.

 

I'll try that as well when I get home tonight.

 

Another issue I came across is when I substituted the bottom TextArea for a ListView, the latter doesn't seem to work and even causes my app to not get past the loading screen.

 

----

 

// Tabbed Pane project template
import bb.cascades 1.0

Page {
property alias driverPhoto : driverPhotoURL.imageSource
property alias driverBio : driverBioText.text
property alias driverName : driverListInfo.title
property alias driverTeam : driverListInfo.description
property alias driverNumber : driverListInfo.status
property alias driverFlag : driverListInfo.imageSource
property alias stat : stat.title
Container {

ImageView {
id: driverPhotoURL
scalingMethod: ScalingMethod.AspectFill
minHeight: 481.0
}


StandardListItem {
id: driverListInfo
}

SegmentedControl {
id: segmentedDrivers
Option {
id: biography
text: "Biography"
value: "biography"
selected: true
}
Option {
id: statistics
text: "Statistics"
value: "statistics"
}
onSelectedIndexChanged: {
var value = segmentedDrivers.selectedValue
console.debug("Selected value: " + value);
if(value == "biography"){
driverBioText.visible = true;
driverStatsList.visible = false;
}
else {driverBioText.visible = false;
driverStatsList.visible = true;
}

}
}

Container {
id: textContainer
rightPadding: 30.0
leftPadding: 30.0
topMargin: 10.0

TextArea {
id: driverBioText
editable: false
visible: true
}

ListView {
id: driverStatsList
visible: false
dataModel: XmlDataModel {
source: "models/driverstats.xml"
}

listItemComponents: [
ListItemComponent {
type: "listItem"

// Use a predefined StandardListItem to represent "listItem"
StandardListItem {
title: ListItemData.statDriver
}
}
]
}
}
}
}

 

----

 

There's the code. I will try the QML binding technique if I can get that to work with the previous method. I just don't want to screw anything up. Something is probably wrong syntactically when I swapped the second TextArea for the ListView.....anyone?

Developer
urbanglowcam
Posts: 148
Registered: ‎10-30-2010
My Device: Bold 9930

Re: Trying to get segmentedControl to toggle between Containers

Peter, your method worked really well, and it's easier for me to understand.

 

I even got the ListView to work substituted with the second TextArea. Thank you both so much.