How to Handle the checkbox ischecked and unchecked event in android

后端 未结 5 1648
慢半拍i
慢半拍i 2021-01-16 02:11

i am new in android.i make a simple maths apps. i use the check box for select right option but problem is here the answer option is not only one but also two,three means

5条回答
  •  甜味超标
    2021-01-16 02:31

    It seems you are having more than one checkbox and you are setting global listener for every checkbox. So, in that case you need to identify the event for specific checkbox also.

    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
        {   
            int id = buttonView.getId();
            if(id == R.id.chk)
            {
              if(chk.isChecked()){
                   forMetchCheckBox.add(String.valueOf(chk.getText()));
                }
               else{
                   forMetchCheckBox.remove(String.valueOf(chk.getText()));
               }
            }
            else if(id == R.id.chk1){
               ....
            }
        }  
    

    and so on, that will make your listener work perfect.

提交回复
热议问题