Checked checkbox in ListView is restored after scrolling

I had the following problem:

I have a ListActivity, its ListView consists of an icon, text, and a checkbox (using LayoutInflater).

The adapter for ListView extends ResourceCursorAdapter (i.e. ListView data source is retrieved from the database, the status of each row is also checked)

Everything works pretty well, except when I uncheck the box or check the box on any line, if I scroll down until the changed box is no longer visible, and then scroll up, the box will be restored to its original state.

The database is changed, this is not a problem (i.e. if I change the line and exit the operation, and enter again, the changed line is displayed OK).

My guess is that it matters to display the list, because for some reason the ListView "displays" the initial state of all the rows when it was first populated when scrolling.

I was looking for this error, but I did not find anyone who had this problem. I appreciate any advice you have.

+5
source share
3 answers

The problem was solved by closing the corresponding cursor after changing the database and reopening it with changeCursor ().

+1
source

This link gives an idea of ​​your problem.

EditText elements in the scroll list lose their changes when scrolling the screen

. 1000 , 1000 EditText , . , 10 , , . EditText , , , before ( ).

+2

, ListAdapter.getView().

, , , , .

getView() . , , getView() , , .

, getView "convertView". , . , "" , , , .

, ( ), , View , , ).

If you decide to use this option to reuse the view, check your logic and make sure that you set all controls to the correct state, since the default layout state may not apply.

+1
source

All Articles