Android问题:使用SimpleCursorAdapter时,如何格式化其中一列

发布于 2024-10-20 21:36:38 字数 703 浏览 2 评论 0原文

我正在尝试创建一个映射到数据库查询的列表,但是,数据库中的字段之一是时间戳,显示时应显示为“3 月 2 日星期三”等日期,而不是实际值数据库类似于 1299517239487...

我可以通过重新表述查询或在执行查询后装饰光标来解决此问题,但我更愿意让简单的光标适配器以特定方式显示此列。

有人知道如何做吗?

一些代码:

// the desired columns to be bound
String[] columns = new String[] { DBHelper.COL_START_TIME, DBHelper.COL_AMOUNT};
// the XML defined views which the data will be bound to
int[] to = new int[] { R.id.dayMonthDate, R.id.amount};

// create the adapter using the cursor pointing to the desired data as well as the layout information
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.single_activity,cursor, columns, to);

我希望能够向适配器添加某种后处理器来解决这个问题。

谢谢!

I'm trying to create a list that is mapped to a database query, however, one of the fields in the database is a timestamp which when displayed should be displayed as a date like "Wednesday, March 2" instead of the actual value in the database which is something like 1299517239487...

I can solve this by rephrasing the query or by decorating the cursor after I do the query, but I would much rather have the simple cursor adapter display this column in that specific way.

Does anyone have any idea on how to do it?

some code:

// the desired columns to be bound
String[] columns = new String[] { DBHelper.COL_START_TIME, DBHelper.COL_AMOUNT};
// the XML defined views which the data will be bound to
int[] to = new int[] { R.id.dayMonthDate, R.id.amount};

// create the adapter using the cursor pointing to the desired data as well as the layout information
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.single_activity,cursor, columns, to);

I would like to be able to add some kind of post processor to the adapter in order to fix that.

Thanks!

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

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

发布评论

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

评论(1

岁月静好 2024-10-27 21:36:38

您可以使用 setViewBinder() SimpleCursorAdapter 的 方法有一个 ViewBinder 手动设置视图的值,但会为每一列调用。

You can use the setViewBinder() method of SimpleCursorAdapter to have a ViewBinder manually set the values for the views but that will get called for every column.

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