0

我有一个使用 RelativeLayout 的自定义 ListView 项目,看起来像这样......

| Time | Title        |
|      | Description  |

注意:左侧的“时间”是单个全高 TextView,其中“标题”和“描述”是单独的“堆叠”文本视图。

ListView 项目表示从带有 SimpleCursorAdapter 的 SQLite DB 中提取的电视节目。这工作正常,但下一步是指示计划录制节目的时间(该应用程序是基于 PC 的 PVR 应用程序的 Android 客户端)。

SQL 查询选择“start_time,title,description,is_set_to_record”,前三个是要绑定到 TextViews 的文本字段,最后一个是布尔值。

看来我可能需要扩展 SimpleCursorAdapter,所以如果 'is_set_to_record' 为真,那么我将所有三个 TextView 的背景颜色设置为不同的颜色。问题是我不知道我应该去哪里做这件事。

这可能吗?如果是这样,任何指向我应该看的地方的指针都将不胜感激。

4

1 回答 1

4

在您扩展的 SimpleCursorAdapter 中,您可以执行以下操作:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
     View v = super.getView(position, convertView, parent);
     Cursor c = getCursor();
     c.moveToPosition(position);
     int col = c.getColumnIndex(is_set_to_record);
     boolean isSet = c.getInt(col) == 1;
     if (isSet) {
         // Set the background color of the text.
     } else {
         // Set the background color to something else.
     }
     return v;
}
于 2011-02-10T01:42:53.157 回答