Android问题:使用SimpleCursorAdapter时,如何格式化其中一列
我正在尝试创建一个映射到数据库查询的列表,但是,数据库中的字段之一是时间戳,显示时应显示为“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 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.