Search code examples
androidandroid-listviewsimplecursoradapterandroid-viewbinder

How can I adapt a cursor to a ListView with a lot of custom behavior?


I'm currently working on an android application that uses a SimpleCursorAdapter with a custom ViewBinder to set specific text color and image visibility on items in my ListView.

However, when my list is longer then the size of a screen, and the user scrolls up and down, the system causes incorrect rows to take on the wrong coloring, etc. My understanding is that this is an issue of the system re-using views as an optimization in scrolling, as explained here.

I'm all for optimization, however I need items to display properly in the ListView. What is the correct way to go about this?

My thinking is that I could implement a CursorAdapter, or preferably a SimpleCursorAdapter, but I don't know how to go about doing so. Alternatively, is it just a matter of setting text color back to its default in my ViewBinder?


Solution

  • Yes, it is a matter of setting every row to a proper color/ values etc. in getView(). As to the simpleCursorAdapter - I found a nice and simple tutorial: http://thinkandroid.wordpress.com/2010/01/09/simplecursoradapters-and-listviews/