Checkbox auto call onCheckedChange when listview scroll?

前端 未结 5 946
终归单人心
终归单人心 2020-12-02 14:26

I have a problem with listview which list item contain a checkbox. When i check a box and scroll list, checkbox sometime auto call oncheckedchange and value of checkbox is c

5条回答
  •  余生分开走
    2020-12-02 15:05

    The ListView recycles the view classes: you will need to explicitly set whether or not the CheckBox is checked in the getView class. So add a check like

    /**
    *    Ensure no other setOnCheckedChangeListener is attached before you manually
    *    change its state.
    */
    mViewHolder.checkbox.setOnCheckedChangeListener(null);
    if(shouldBeChecked) mViewHolder.checkbox.setChecked(true);
    else mViewHolder.checkbox.setChecked(false);
    

    before you call setOnCheckedChangeListener.

提交回复
热议问题