Android, Checkboxes Randomly Checked/Unchecked in Expandable List

前端 未结 2 1599
一个人的身影
一个人的身影 2021-01-15 03:16

Using this Expandable List checkbox example code as an baseline, I am trying to save and maintain the checkbox state. However, random checkboxes are being checked and unchec

2条回答
  •  盖世英雄少女心
    2021-01-15 04:12

    This is a very old question, but I struggled with the same problem so here is my answer for anybody looking:

    The simplest way is to use CheckBox.onClickListener instead of onCheckedChangeListener.

    This is only mildly annoying in terms of rearranging your logic, but will ensure that when the boxes are unchecked randomly (by, e.g. expanding an adjacent group) the event will not fire.

    Honestly I think this should be considered a bug, even though I'm sure the behaviour can be explained from the Android source.

提交回复
热议问题