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
Developer
klz
Posts: 132
Registered: ‎08-24-2011
My Device: Z10 LE + Playbook
Accepted Solution

Mark selected item in listview

Hello experts,

 

So I need to show a selected list item by placing a checkmark next to it (in cell). Only one cell can be selected. So does anybody have a solution which can be shared? Or some advises to how that can be done properly. I would be very thankful.

Thank you!
----------------------------
My Apps: Alchemy Game | Image Resizer | Jam! | Traffic Signs: USA | Radio Record
My Blog: http://bb10pro.com
Please use plain text.
Developer
strobejb
Posts: 282
Registered: ‎10-15-2012
My Device: bb10 developer

Re: Mark selected item in listview

The StandardListItem component isn't easily extendable. The 'normal' way to do this is to define your own ListItemCompnent using a Container as the outer control, and then put images, labels, check-boxes inside as you see fit
Please use plain text.
Regular Contributor
Q-T
Posts: 94
Registered: ‎12-02-2011
My Device: non-Blackberry user

Re: Mark selected item in listview

THe code below might help you get started:

 

MyCheckBoxItem::MyCheckBoxItem(Container *parent): CustomControl(parent) {
    Container *itemContainer = new Container();
    itemContainer->setTopPadding(15.0f);
    itemContainer->setBottomPadding(15.0f);
    itemContainer->setLeftPadding(32.0f);
    itemContainer->setHorizontalAlignment(HorizontalAlignment::Fill);
    DockLayout *itemLayout = new DockLayout();
    itemContainer->setLayout(itemLayout);
    itemContainer->setPreferredWidth(700.0f);
    cb = new CheckBox();
   cb->setHorizontalAlignment(HorizontalAlignment::Fill);
    itemContainer->add(cb);
    setRoot(itemContainer);
}
void MyCheckBoxItem::setText(QString &str) {
  cb->setText(str);
}

void MyCheckBoxItem::setChecked(bool check)
{
    cb->setChecked(check);
}

bool MyCheckBoxItem::isChecked()
{
    return cb->isChecked();
}
void MyCheckBoxItem::reset(bool selected, bool activated)
{
 
}

 

Then where you have a list created you can add a slot to the selection signal such as the following:

void MyPage::activationChangedSlot(QVariantList vl,bool bstatus) {
    qDebug() << "Activation, status =  " << bstatus;
    bool setSelected = true;
    if (bstatus) {
        listView->clearSelection();
        if (listView->isSelected(vl))
            setSelected = false;
        listView->select(vl, setSelected);
    }

}

 

I think you will have to add handlers to the MyCheckItem above to do the checking & unchecking in the selecth slot which I didn't  show. 

 

Hope this is of some value to you

 

 

Please use plain text.
Developer
Developer
klz
Posts: 132
Registered: ‎08-24-2011
My Device: Z10 LE + Playbook

Re: Mark selected item in listview

Hello everyone. 

 

I've done the following way. In onTriggered within a listview I added these 2 lines:

clearSelection();
select(indexPath, true);

 

That's it.

Thank you!
----------------------------
My Apps: Alchemy Game | Image Resizer | Jam! | Traffic Signs: USA | Radio Record
My Blog: http://bb10pro.com
Please use plain text.