我有一個問題,我有一個日期時間值的字段,並希望在列表視圖上顯示格式化的值。 有人可以看看我的代碼,並幫助這個嗎?從SQLite轉換日期和填充列表視圖
cursor = db.getAllSms();
startManagingCursor(cursor);
int mTime= cursor.getColumnIndex(DBAdapter.KEY_DATETIME);
String[] from = new String[cursor.getCount()];
int[] to = new int[] {R.id.label};
int counter = 0;
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()){
SimpleDateFormat sdf = new SimpleDateFormat("dd MMMM yyyy HH:mm");
Date resultdate = new Date(cursor.getLong(mTime));
String mDateTime = sdf.format(resultdate);
from[counter] = mDateTime;
counter++;
}
SimpleCursorAdapter users = new SimpleCursorAdapter(this, R.layout.sms_row, cursor, from, to);
setListAdapter(users);
是什麼問題? – confucius 2012-02-15 23:44:56