I have a checkbox set but only wanted one selected

Asked

Viewed 1,864 times

1

I have a set of checkbox but only wanted a selected one and, if they selected another, the one that was selected.

I’ve tried that, but it doesn’t work:

if (chkfemenino.isChecked()) {
    params.add(new BasicNameValuePair("genero", generofem));
    chkmasculino.setChecked(false);         
}
if (chkmasculino.isChecked()) {
    params.add(new BasicNameValuePair("genero", generomasc));
    chkfemenino.setChecked(false);          
}
  • It is simple to just desilect when selecting the other. It has to be in the onClick of each checkbox.

  • That is, when you click on chkfemenino is that you put the chkmasculino to false.

  • 3

    Or use a RadioButton.

  • yes I’ve thought about the radiobutton but kind would really prefer checkboxs.. if it were possible..

  • 2

    The question is valid as knowledge about manipulating events in checkboxes, but I agree with @ramaral: use radiobuttons. The user may have different preferences from your, but mainly remember that the components exist for different purposes (capture only one or multiple choices). Thus, there is a standardization of behavior that is denoted by distinctions in component designs (checkboxes are usually square and scratched, radiobuttons are usually round and filled), which is expected by users. Changing this can cause confusion in users.

  • luis the only problem that I will want in my program options of multiple choice and options only one choice and not for different things that wanted only checkboxs

  • Yeah, I get it. My only point is that by doing this you will be going against a well-established user interaction approach, which uses checkboxes for multiple choices and radiobuttons for unique choices. And, excuse my sincerity, but the motivation for this seems to be just your personal preference. You can do as you prefer (the program is yours), but just note that this can cause confusion or some discomfort to your users, discouraging the use of the program. :)

  • Look at the type of user usability/experience problem that does not follow these conventions can generate: http://www.nngroup.com/articles/checkboxes-vs-radio-buttons/

  • Just to show that even the visual quality (artistic) can be worked without changing the convention, one more link for you (see the accepted answer). : ) http://ux.stackexchange.com/questions/12512/are-round-check-boxes-confusing-or-an-accepted-standard?rq=1

Show 4 more comments

1 answer

4


It’s simple enough to desiccate one CheckBox when you select the other:

chkfemenino.setOnCheckedChangeListener(new OnCheckedChangeListener() 
{
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 
    {
        if (buttonView.isChecked()) 
        {
            ischkfeminino  = isChecked;
            ischkmasculino = false;

            chkfeminino. setChecked(ischkfeminino );
            chkmasculino.setChecked(ischkmasculino);
        }
    }
});

And you do the same for the chkmasculino.

  • you put that in the oncreate?

  • Yeah, or in some function, as long as you call that function on onCreate

  • OK thanks J orge b

Browser other questions tagged

You are not signed in. Login or sign up in order to post.