基于 SimpleCursorAdapter 字段更改 ListView 项的背景颜色?

发布于 2024-10-17 06:02:57 字数 569 浏览 7 评论 0原文

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

| Time | Title        |
|      | Description  |

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

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

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

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

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

I have a custom ListView item using RelativeLayout which looks like this...

| Time | Title        |
|      | Description  |

NOTE: The lefthand 'Time' is a single full height TextView with 'Title' and 'Description being individual 'stacked' TextViews.

The ListView items represent TV programmes extracted from a SQLite DB with a SimpleCursorAdapter. This works fine but the next step is to indicate when a programme has been scheduled to record (the app is an Android client for a PC-based PVR application).

The SQL query selects 'start_time,title,description,is_set_to_record' the first three being text fields to bind to the TextViews and the last being boolean.

It seems I probably need to extend SimpleCursorAdapter so if 'is_set_to_record' is true then I set the background colour of all three TextViews to a different colour. The problem is that I don't know where I should be looking to do this.

Is this possible? If so, any pointers to where I should look would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离鸿 2024-10-24 06:02:57

在扩展的 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;
}

In your extended SimpleCursorAdapter you can do something like this.:

@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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文