Android setOnCheckedChangeListener calls again when old view comes back

前端 未结 8 1928
鱼传尺愫
鱼传尺愫 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
    
          }
        });
    
    0 讨论(0)
  • 2020-12-14 07:13

    I faced the same problem and struggled for several hours seeing all discussions related to this. I tried to fix this by keeping viewHolder.checkBox.setTag(groupPosition);
    this statement before viewHolder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() this listener. And the code works exactly as expected.

    0 讨论(0)
提交回复
热议问题