我有一个应用程序正在检索从 1970 年开始以毫秒为单位存储为字符串的日期,例如 1324657734883
.
我有一个ListView
显示这个日期的。我想在数据库中显示DateTime
此字段中的 joda。我的视图显示列表视图并通过使用填充它,startManagingCursor()
所以我认为在填充milisec
到.DateTime
listview
有没有办法解决这个问题,或者我是否必须存储一个 DateTime,如果是这样,我需要声明什么列类型来存储这种类型的数据?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
nfcscannerapplication = (NfcScannerApplication) getApplication();
// setup UI
setContentView(R.layout.viewtransactions);
setTitle(getCarername() + " has completed " + nfcscannerapplication.loginValidate.getNumberOfTransactions() + " visits today");
//transactionCount = (TextView)findViewById(R.id.textviewtransactionsfordaycount);
viewTransactions = (ListView) findViewById(R.id.listviewtransactions);
//transactionCount.setText("You have completed 6 transactions today");
// get data
cursor = nfcscannerapplication.loginValidate.queryAllFromTransactions();
startManagingCursor(cursor);
// setup adapter and show the data
String[] from = {
LoginValidate.C_NAME, LoginValidate.C_TAG_SCAN_TIME,
LoginValidate.C_TAG_SCAN_TIME};
int[] to = { R.id.rowcarername, R.id.rowsignedinoutstatus, R.id.rowsenttoserverat };
adapter = new SimpleCursorAdapter(nfcscannerapplication, R.layout.rowdataactual,
cursor, from, to);
viewTransactions.setAdapter(adapter);
}
}
.
[update1] 公共类 ViewTransactions 扩展 NfcBaseActivity{
private static final String TAG = ViewTransactions.class.getSimpleName();
NfcScannerApplication nfcscannerapplication;
Cursor cursor;
ListView viewTransactions;
SimpleCursorAdapter adapter;
MyAdapter myAdapter;
//TextView transactionCount; //now written to status bar
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
nfcscannerapplication = (NfcScannerApplication) getApplication();
// setup UI
setContentView(R.layout.viewtransactions);
setTitle(getCarername() + " has completed " + nfcscannerapplication.loginValidate.getNumberOfTransactions() + " visits today");
//transactionCount = (TextView)findViewById(R.id.textviewtransactionsfordaycount);
viewTransactions = (ListView) findViewById(R.id.listviewtransactions);
//transactionCount.setText("You have completed 6 transactions today");
// get data
cursor = nfcscannerapplication.loginValidate.queryAllFromTransactions();
startManagingCursor(cursor);
// setup adapter and show the data
String[] from = {
LoginValidate.C_NAME, LoginValidate.C_TAG_SCAN_TIME,
LoginValidate.C_TAG_SCAN_TIME};
int[] to = { R.id.rowcarername, R.id.rowsignedinoutstatus, R.id.rowsenttoserverat };
myAdapter = new MyAdapter(nfcscannerapplication, R.layout.rowdataactual,
cursor, from, to);
viewTransactions.setAdapter(adapter);
}
class MyAdapter extends SimpleCursorAdapter {
public MyAdapter(Context context, int layout, Cursor c, String[] from,
int[] to) {
super(context, layout, c, from, to);
}
@Override
public
View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
if(v == null)
return null;
Cursor c = (Cursor)getItem(position);
String val = c.getString(c.getColumnIndex(LoginValidate.C_TAG_SCAN_TIME));
Date dt = new Date(Long.parseLong(val));
SimpleDateFormat df = new SimpleDateFormat("dd MMMM yyyy");
String res = df.format(dt);
((TextView)v.findViewById(R.id.rowsignedinoutstatus)).setText(res);
((TextView)v.findViewById(R.id.rowsenttoserverat)).setText(res);
return v;
}
}
}