Android setOnCheckedChangeListener calls again when old view comes back

前端 未结 8 1968
鱼传尺愫
鱼传尺愫 2020-12-14 06:39

I cannot solve an issue with the getGroupView-method.

the problem is that the listener setOnCheckedChangeListener is getting invoked to many times.

Let say

8条回答
  •  甜味超标
    2020-12-14 07:09

    What version of Android are you using?

    It seems to be an issue for multiple components, especially with a checkedChange() method (CheckBox, RadioButton) and I can't provide a good explanation why it is happening.

    I would assume because it registers the change of the position state and grabs the change of other properties? A similar issue was addressed here

    In any case, a workaround around this could be to add an OnClickListener().

    CheckBox yourCheckBox = (CheckBox) findViewById (R.id.yourId);
    
    yourCheckBox.setOnClickListener(new OnClickListener() {
    
          @Override
          public void onClick(View v) {
                    //is chkIos checked?
            if (((CheckBox) v).isChecked()) {
                             //Case 1
            }
            else 
              //case 2
    
          }
        });
    

提交回复
热议问题