我有一个包含 {Name, Time (UTC format) , Latitude, Longitude} 列的数据库表
我使用带有 SimpleCursorAdapter 的 ListActivity 显示表格。
我希望时间列以人类可读的格式 (13-07-2010 10:40) 而非 UTC 格式 (18190109089) 显示时间。
如何指定时间列中的值需要一些过滤/调整?
可能的解决方案(有问题):
SimpleCursorAdapter 提供方法:
setCursorToStringConverter(SimpleCursorAdapter.CursorToStringConverter cursorToStringConverter);
指定一个类如何将 Cursor 转换为 CharSequence (convertToString(Cursor cursor). 无论如何,我不知道返回 CharSequence 参数应该采用哪种格式!
最佳答案
格式化光标值的最简单方法是使用 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;
}
});
关于android - 使用 SimpleCursorAdapter 从 Cursor 更改值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3609126/