javaandroidcheckboxandroid-checkbox

Why after action associated with one checkbox both checkboxes are are disabled?


everyone! I want to implement app that:

  1. Click on the checkbox
  2. Move to new action
  3. Complete new action
  4. Return to checkbox action
  5. Set clicked checkbox checked and disabled

In my code when I try to implement it the second checkbox is also checked and disabled despite the fact that I haven't clicked it.

Please help! See my code below:

     public void CheckboxCare(@NonNull View v){
    switch (v.getId()){
        case R.id.checkbox_p2106:
            if(pref.contains("checked") && pref.getBoolean("checked", false) == true){
                setChecked(P2106);
                disableCheckbox(P2106);
            }else{
                setNotChecked(P2106);
            }
            checkboxListener(P2106);
            break;
        case R.id.checkbox_mp2106:
            if(pref.contains("checked") && pref.getBoolean("checked", false) == true){
                setChecked(MP2106);
                disableCheckbox(MP2106);
            }else{
                setNotChecked(MP2106);
            }
            checkboxListener(MP2106);
            break;
    }
}

Solution

  • Create object for each check box send on that function call based on your requirement

    public void CheckboxCare(@NonNull View v){
    switch (v.getId()){
        case R.id.checkbox_p2106:
                         {
                         // write code here
                         }
        case R.id.checkbox_mp2106:
            if(pref.contains("checked") && pref.getBoolean("checked", false) == true){
                setChecked(checkbox_p2106);// enable one
                disableCheckbox(checkbox_p2106);// disable second
            }else{
                setNotChecked((CheckBox) v);
            }
            checkboxListener((CheckBox) v);
            break;
    }
    }