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: 73
Registered: ‎05-03-2011
My Device: 9550
My Carrier: verison

How to add checkbox in listview item?

I want to show item select status, so I add checkbox in listview item, but how to strict to only one item can be selected? and is there any way to handle each checkbox notify message. I have code below:

 ListView {
                id:listView               
                property variant oldItemPath: 0
                
                dataModel: currencyDataModel
                
                listItemComponents: [
                    ListItemComponent {
                        type: "item"
                        Container{
                            id:addItem
                            
                            leftPadding: 30
                            preferredHeight: 200
                            
                            layout: StackLayout { orientation: LayoutOrientation.LeftToRight }
                            
                            ImageView{
                                layoutProperties: StackLayoutProperties {
                                    spaceQuota: 1
                                }
                                verticalAlignment: VerticalAlignment.Center
                                imageSource: "asset:///images/"+ListItemData.code+".png"  
                            }
                            Label {
                                id:srcCodeName
                                verticalAlignment: VerticalAlignment.Center
                                layoutProperties: StackLayoutProperties {
                                    spaceQuota: 1.5
                                }
                                
                                text: ListItemData.code +": "
                                
                                textStyle.base: SystemDefaults.TextStyles.TitleText
                                textStyle.color: Color.White
                            }
                            Label {
                                id:srcCountryName
                                verticalAlignment: VerticalAlignment.Center
                                layoutProperties: StackLayoutProperties {
                                    spaceQuota: 6.5
                                }
                                
                                text: ListItemData.name
                                
                                textStyle.base: SystemDefaults.TextStyles.TitleText
                                textStyle.color: Color.White
                            }                                
                            CheckBox {
                                id: checkBox1
                                verticalAlignment: VerticalAlignment.Center
                                layoutProperties: StackLayoutProperties {
                                    spaceQuota: 1
                                }
                                checked: addCurrencyItem.ListItem.selected
                               
                            }
                        
                        }
                    
                    }
                
                ]

 

Author of pairs and Gradient
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: How to add checkbox in listview item?

Strictly speaking if you can only select one at a time you should use a radiobutton.

However that aside you will need to implement your own logic, say a piece of java code in your listview called from the listitemcomponant.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Developer
Posts: 132
Registered: ‎08-24-2011
My Device: Z10 LE + Playbook
My Carrier: MTS Ukraine

Re: How to add checkbox in listview item?

[ Edited ]

Do you really need a checkbox or just need to show selected item? 

 

If you need to just to show selected item you can do that the following way. Add that 2 lines to onTriggered within a ListView

 

onTriggered:{
    clearSelection();
    select(indexPath, true);
}

 

Thank you!
----------------------------
My Apps: Alchemy Game | Image Resizer | Jam! | Traffic Signs: USA | Radio Record
My Blog: http://bb10pro.com
Developer
Posts: 73
Registered: ‎05-03-2011
My Device: 9550
My Carrier: verison

Re: How to add checkbox in listview item?

I have tried this way, it seems that you can select multi item once, the clearselection not work well, I don't know why?

Author of pairs and Gradient
Developer
Developer
Posts: 132
Registered: ‎08-24-2011
My Device: Z10 LE + Playbook
My Carrier: MTS Ukraine

Re: How to add checkbox in listview item?

Have no idea why becaue it works properly for me. I needed to do the same thing some time ago. 

Thank you!
----------------------------
My Apps: Alchemy Game | Image Resizer | Jam! | Traffic Signs: USA | Radio Record
My Blog: http://bb10pro.com
Highlighted
Developer
Posts: 73
Registered: ‎05-03-2011
My Device: 9550
My Carrier: verison

Re: How to add checkbox in listview item?

if you just click the item, there will be work, but if you click item first, then click another checkbx(just click the checkbox), you will find two checkboxs checked, so I should fix the problem.

Author of pairs and Gradient