Android Radio buttons in a custom listview changes its state when we scroll the list

前端 未结 3 530
刺人心
刺人心 2021-01-05 22:01

I am a beginner and facing a problem where I am creating a ListView with two RadioButtons and a TextView. Everything goes fine, but wh

3条回答
  •  既然无缘
    2021-01-05 22:23

    You adapter is always recreating the item for the list view. When he does that, he takes a "fresh" view and you have to set the data to this view using your array.

    In your case, if you want to "save" the state of the radio button, you have to save this data as part of the adapter data, meaning in the array. I suggest you add a field to your Option object and use it save the last value of the radio button. afterwards, when they line Option option = data[position]; is being called, you can then reclaim the last value and display it on screen.

提交回复
热议问题