从游标使用SimpleCursorAdapter更改值 [英] Changing values from Cursor using SimpleCursorAdapter
问题描述
我与列的数据库表{名称,时间(UTC格式),纬度,经度}
I have database table with the columns {Name, Time (UTC format) , Latitude, Longitude}
我显示使用ListActivity与SimpleCursorAdapter表。
I display the table using a ListActivity with a SimpleCursorAdapter.
我想该列的时间显示在人类可读的格式(13-07-2010 10:40)的时间,而不是UTC格式(18190109089)。
I would like that the column Time show the time in a human readable format (13-07-2010 10:40) rather than in UTC format (18190109089).
如何指定从列时间值需要一些过滤/适应?
How can I specify that the values from column Time need some filtering/adaptation?
可能的解决方案(有问题):
POSSIBLE SOLUTION (with a problem):
SimpleCursorAdapter提供的方法:
SimpleCursorAdapter offers the method:
setCursorToStringConverter(SimpleCursorAdapter.CursorToStringConverter cursorToStringConverter);
要指定一个类,它是能够将光标转换为CharSequence的(convertToString(光标指针)如何。 反正我不知道哪种格式应该是回归的CharSequence paramater!
to specify how a class that is able to convert a Cursor to CharSequence (convertToString(Cursor cursor). Anyway I don't know in which format should be the return CharSequence paramater!
推荐答案
格式化光标值的最简单的方法是使用SimpleCursorAdapter.setViewBinder(..):
The simplest way to format a cursor value is to use SimpleCursorAdapter.setViewBinder(..):
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.list, cursor,
new String[] { Definition.Item.TITLE, Definition.Item.CREATE_DATE }, new int[] { R.id.title, R.id.createDate});
adapter.setViewBinder(new ViewBinder() {
public boolean setViewValue(View aView, Cursor aCursor, int aColumnIndex) {
if (aColumnIndex == 2) {
String createDate = aCursor.getString(aColumnIndex);
TextView textView = (TextView) aView;
textView.setText("Create date: " + MyFormatterHelper.formatDate(getApplicationContext(), createDate));
return true;
}
return false;
}
});
这篇关于从游标使用SimpleCursorAdapter更改值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!