如何处理机器人的复选框和器isChecked选中事件

如何处理机器人的复选框和器isChecked选中事件

问题描述:

我在android.i新做一个简单的数学应用程序。
我使用的选择权选项,但问题的复选框是这里的答案选项是不是只有一个,而且二,三方式多选择,所以我使用复选框

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 multi select so i use the check box

chkOption.setOnCheckedChangeListener(this);

事件,并试图处理this.and存储在一个Arraylist.but选择值时,我选择的选项值数组列表中添加但是当我做取消(取消选取),那么也该事件发生和值数组列表中添加。
我的code是低于

event and try to handle this.and store the select value in one Arraylist.but when i select option the value is add in arrayList but when i do uncheck(Diselect) then also the event is occur and the value add in arraylist. my code is below

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
    {   
        CheckBox chk=(CheckBox) buttonView;
        if(chk.isChecked())
        {
            forMetchCheckBox.add(String.valueOf(chk.getText()));            
        }
    }   

forMetchCheckbow是我的字符串ArrayList的。所以我能怎么办呢?
如何处理这个问题。
如果任何用户取消选项,那么该复选框选择值从ArrayList.it`s消除可能的?

forMetchCheckbow is my String ArrayList .So i can what to do? How to Handle this problem. if any user deselect the option then the checkbox select value is remove from ArrayList.it`s possible?

看来你有一个以上的复选框,并要为每一个复选框,设置全局监听器。所以,在这种情况下,你需要indenify特定复选框也该事件。

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 indenify 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.