Checking Multiple Checkboxes in Android

前端 未结 1 778
栀梦
栀梦 2020-12-21 02:29
CheckBox checkOne = (CheckBox) findViewById(R.id.checkOne);
checkOne.setSelected(true);

CheckBox checkTwo = (CheckBox) findViewById(R.id.checkTwo);
checkTwo.setSele         


        
相关标签:
1条回答
  • 2020-12-21 03:11

    If the parent LinearLayout contains only the checkboxes, you can do this:

    //ll is the LinearLayout holding the children
    for(int i = 0; i < ll.getChildCount(); i++) {
        ((CheckBox)ll.getChildAt(i)).setChecked(true);
    }
    

    if you have more views in the LinearLayout you could add a check like this:

    for(int i = 0; i < ll.getChildCount(); i++) {
        View v = ll.getChildAt(i);
        if(v instanceof CheckBox) {
            ((CheckBox)v).setChecked(true);
        }
    }
    
    0 讨论(0)
提交回复
热议问题