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

BlackBerry® World™ Development

Reply
New Contributor
josepatience
Posts: 8
Registered: ‎12-18-2012
My Device: BB 10

Help with saving to XML file opend in a list.

Hi,

 

I created a list based on a XML file.

for each list item there are 3 radio buttons to select.

I want to save the radio button selection back into the xml file as a child of the current list item  ie:< ListItem ......... child="rediobuton selection" />

here is my code:

Plz help.

import bb.cascades 1.0

Page {
     actions: [
                // create navigation panel actions here
                ActionItem {
                    title: qsTr("Create a report")
                    onTriggered: {
                        imgView.imageSource = "asset:///images/picture1br.png"
                    }
                }
            ]
    Container {
        // the childcount for the list item
        property alias listChildCount: chList.childCount
        property alias radioIndex: radioGp.selectedIndex
        property alias currentListPostion: chList.ListItemData.title 
    
       ListView {
           id: chList
                   dataModel: XmlDataModel {
                       source: "models/Chapter2.xml"
                   }
         
                   listItemComponents: [
                       ListItemComponent {
                           type: "header"
                           Header {
                               title: ListItemData.title
                       }
                       },
                       ListItemComponent {
                           type: "listItem"
                       Container {
                        layout: DockLayout {}

                        // RadioGroup
                        // This is a reset function for the component RadioGroup. If called, it removes any
                        // selected RadioOption.
                        function resetSelectedOption() {
                            radioGp.resetSelectedIndex();
                        }

                        // This function allows selecting a specific index in the RadioGroup.
                        function setSelectedIndex(index) {
                            radioGp.setSelectedIndex(radioIndex);
                        }
                        RadioGroup {
                            id: radioGp
                            dividersVisible: false
                            preferredWidth: 150
                            minWidth: 149.0
                            Option {
                                id: option1
                                text: "H"
                                //     value: text
                            }
                            Option {
                                id: option2
                                text: "M"
                                //      value: text
                            }
                            Option {
                                id: option3
                                text: "L"
                                //        value: text
                            }
                            // When a new option is selected, we print the selection to the console.
                            onSelectedValueChanged: {
                                console.debug("New filling set: " + selectedValue);
                                if(selectedIndex >= 0) {
                                radioIndex = radioGp.selectedIndex
                                currentListPostion = chList.XmlDataModel.Data();
                                chList.XmlDataAccess.save(currentListPostion+1+"radioValue="&radioIndex, "..asset:///models/Chapter2.qml" )
                            }//endif
                            }
                        }
                        Divider {} // at the end of each list item
                        LabelLabel {
                            text: ListItemData.title
                            bottomPadding: 50.0
                            leftPadding: 150.0
                        }// end of LabelLabel
                        
                    } // end of Container
                } // end of second ListItemComponent
            ] // end of listItemComponents list
        } // end of ListView
    }
}