我知道您可以创建自定义 Adapter
扩展 BaseAdapter
并创建各种布局,这些布局可以根据 AdapterView
所在的行进行扩充..
但是有什么方法可以使用 SimpleCursorAdapter
进行简单的定制吗?
例如。我有一个数据库,我想查询它并将结果返回到具有交替行布局的 ListView
。
SimpleCursorAdapter
可以吗?或者有什么优雅的解决方案吗?
干杯
最佳答案
But is there any way to get a simple amount of customization with a SimpleCursorAdapter?
就像 BaseAdapter 一样,您可以扩展 CursorAdapter 或 SimpleCursorAdapter 来进行自定义。
Eg. I have a database and I would like to query it and return the results to a ListView with alternating row layouts.
如果你只是改变像行颜色这样的小东西,你可以简单地覆盖 bindView()
并检查 if(cursor.getPosition() % 2 == 0)
(或 == 1
)设置适当的背景颜色。
如果您在每个布局中使用不同类型或数量的 View ,则需要覆盖 getViewTypeCount()
和 getItemViewType()
。然后在 newView()
中使用 getItemViewType()
来加载适当的布局,并在 bindView()
中使用来显示适当的数据。
关于Android - SimpleCursorAdapter 是否允许像 BaseAdapter 这样的多种布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13942238/