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

Java Development

Reply
Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom
Accepted Solution

Making one Checkbox field selectable at a time

Hey Everyone

 

I have got three checkboxfields in my code and I would just like to know how to make one checkboxField Selectable at a time. 

 

Please help me..

 

Thank you

Developer
Posts: 16,986
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Making one Checkbox field selectable at a time

use a fieldchangelistener and uncheck all other boxes when one is checked.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: Making one Checkbox field selectable at a time

Please can you help me through this I am not using the correct functions somewhere...

final CheckboxField Checkbox1=new CheckboxField("",false) {
      protected boolean invokeAction(int action){
          fieldChangeNotify(1);
          this.setChecked(true);
             return true;
      }
};

FieldChangeListener CheckBoxListener = new FieldChangeListener() {
    public void fieldChanged(Field field, int context) {

        if(Checkbox1.getChecked() == true){
            Checkbox2.setChecked(false);
             Checkbox3.setChecked(false);

        }else if(Checkbox2.getChecked() == true){

         Checkbox1.setChecked(false);
        Checkbox3.setChecked(false);
}else if(Checkbox3.getChecked() == true){
       Checkbox1.setChecked(false);
       Checkbox2.setChecked(false);
}
}
};

 

Checkbox1.setChangeListener(CheckBoxListener);

Checkbox2.setChangeListener(CheckBoxListener);
Checkbox3.setChangeListener(CheckBoxListener);

add(Checkbox1);

add(Checkbox2);

add(Checkbox3);

 

Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: Making one Checkbox field selectable at a time

found a sollution ...

 

A Radio group only allows one Field to be selectable at a time....