I know you can create a custom Adapter extending BaseAdapter and create various layouts which can be inflated depending on which row the AdapterView is at..
But is there any way to get a simple amount of customization with a SimpleCursorAdapter?
Eg. I have a database and I would like to query it and return the results to a ListView with alternating row layouts.
Will SimpleCursorAdapter do? Or are there any elegant solutions for this?
Cheers
Just like BaseAdapter, you can extend CursorAdapter or SimpleCursorAdapter to do your customization.
If you are only alternating a minor thing like row color, you can simply override
bindView()and checkif(cursor.getPosition() % 2 == 0)(or== 1) to set the appropriate background color.If you are using different types of or numbers of Views in each layout, you need to override
getViewTypeCount()andgetItemViewType(). Then usegetItemViewType()innewView()to load the appropriate layout and inbindView()to display the appropriate data.