0

i m trying to set the attribute of one check box to selected after i click the first check box

CheckBox check = (CheckBox) findViewById(R.id.checkBox);

assume there is three check boxes,

[] 1
[] 2
[] 3

if i tick check box 1 the second check box will also be marked as checked.

[✔] 1
[✔] 2
[] 3

the thing is they have the same name and i was wondering if it is possible. i would gladly appreciate any comments and answers.

Deps
  • 1

1 Answers1

0

I think you must not have the same name for the three checkbox. So, in this case, you can do the following thing :

CheckBox check1 = (CheckBox) findViewById(R.id.checkBox1);
CheckBox check2 = (CheckBox) findViewById(R.id.checkBox2);
CheckBox check3 = (CheckBox) findViewById(R.id.checkBox3);
check1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
            check2.setChecked(true);
        }
    }
});
Nicolas Mauti
  • 506
  • 3
  • 13
  • is it possible to use the objects ID or TAG to make it selected? if it is how can i do that... btw, thanks for answering.. – Deps Sep 22 '15 at 12:43
  • From the docs : "Any View object may have an integer ID associated with it, to uniquely identify the View within the tree." (http://developer.android.com/guide/topics/ui/declaring-layout.html). For the tags, you can try this http://stackoverflow.com/questions/5062264/find-all-views-with-tag – Nicolas Mauti Sep 22 '15 at 12:54