How can I change the background color of list items based on the data being displayed in each item?

前端 未结 2 1198
星月不相逢
星月不相逢 2021-01-25 20:25

I have a list of orders in SQLite which vary in status: assigned, loaded, delivered. I\'d like for each of those orders, when displayed in the list, to have a different colored

2条回答
  •  被撕碎了的回忆
    2021-01-25 21:07

    I would say try to extend CursorAdapter for binding your database with a ListView. And then you can override ListView.dispatchDraw() to customize your Paint object.

    Or maybe it's helpful to check this: Customizing Android ListView Items with Custom ArrayAdapter

    It uses different images based on weather status. Porting to your problem, you may use 9-patch or programmatically created Drawables as backgrounds, rather than changing stuff in Paint.

提交回复
热议问题