编辑光标数据显示ListAdapter它在ListView前 [英] Editing cursor data before ListAdapter displays it in the ListView

查看:77
本文介绍了编辑光标数据显示ListAdapter它在ListView前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次检索的SQLite数据库信息到游标。

I first retrieve information from the SQLite database into a cursor.

光标包含格式的时间戳列: YYYY-MM-DD HH:MM:SS.SSS ,例如 2010- 08-27 21:25:30.575

The cursor contains a timestamp column in the format: yyyy-MM-dd HH:mm:ss.SSS, for example, 2010-08-27 21:25:30.575

一旦检索到,我设置了 SimpleCursorAdapter 像这样(code简体):

Once retrieved, I set aSimpleCursorAdapter like so (code simplified):

SimpleCursorAdapter adapter = 
            new SimpleCursorAdapter(this, R.layout.row_layout, cursor, new String{KEY_TITLE, KEY_TIMESTAMP}, new int[]{ R.id.title, R.id.timestamp } );
    setListAdapter(adapter);

在code成功地显示在上述格式的日期和时间,但我想(基于如果可能的区域或者用户的格式)来显示刚刚在DD / MM / YYYY格式的日期。

The code successfully displays the time and date in the format described above, but I would like to display just the date in DD/MM/YYYY format (or perhaps the user's format based on locale if possible).

如何与SimpleCursorAdapter介入的日期改变我的preferred格式?

N.B。我愿意改变信息传递给适配器,如果它简化问题的方式。我也不会介意改光标SQLite的查询,如果有SQLite的内置的格式。

N.B. I would be willing to change the way information is passed to the adapter if it simplifies matters. I also wouldn't mind changing the SQLite query for the cursor if SQLite has a built-in formatter.

推荐答案

查询方式:

SELECT strftime('%d/%m/%Y',TimeStampField) FROM MyTable...

由于SQLite的将返回字符串的所有领域,你需要为你的SimpleCursorAdaptor做的是解析日期,然后改变它。我很想说这是更简单和更清洁有它通过的SQLite摆在首位完成。

Because SQLite will return strings for all fields, what you would need to do for your SimpleCursorAdaptor is parse the date and then transform it. I'm tempted to say it's simpler and cleaner to have it done by SQLite in the first place.

这篇关于编辑光标数据显示ListAdapter它在ListView前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆