Refreshing checkbox state in a listview

后端 未结 2 1778
轻奢々
轻奢々 2020-12-18 15:25

I have list view with custom row layout (list_row.xml) that contains CheckBox element:



        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-18 15:36

    What I have found is that because getView is redrawing and recycling the list item on scroll one needs to state explicitly when the check box should be checked and when not (similar solution for the selected item's background colour) in a statment like

    if (condition){...set check box checked code...}else{...set check box unchecked code...}

    The checkbox state can be derived from an array which must be updated every time the user check or uncheck the box in the list view.

提交回复
热议问题