Android - Does SimpleCursorAdapter allow multiple layouts like BaseAdapter?

六眼飞鱼酱① 提交于 2019-12-04 11:24:49

But is there any way to get a simple amount of customization with a SimpleCursorAdapter?

Just like BaseAdapter, you can extend CursorAdapter or SimpleCursorAdapter to do your customization.

Eg. I have a database and I would like to query it and return the results to a ListView with alternating row layouts.

If you are only alternating a minor thing like row color, you can simply override bindView() and check if(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() and getItemViewType(). Then use getItemViewType() in newView() to load the appropriate layout and in bindView() to display the appropriate data.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!