Pigeon android noobie 在这里。我正在尝试格式化数据库值以在 DBcolumn 上存储时间。我正在使用的代码根本没有格式化数据,只是显示格式化的数据必须接近:)
public void PopulateListViewFromDatabase() {
Cursor cursor = myDb.getAllRows();
startManagingCursor(cursor);
// Setup mapping from the cursor to view fields
String[] fromFieldNames = new String[] {
DBAdapter.KEY_START,
DBAdapter.KEY_FINISH,
DBAdapter.KEY_ACTIONHRCOUNT,
DBAdapter.KEY_BANGCOUNT,
DBAdapter.KEY_RANDOMOPT
};
int[] to=new int [] {
R.id.txtStartTime,
R.id.txtFinishTime,
R.id.txtActionCount,
R.id.txtBangCount,
R.id.checkRandom
};
//Create adaptor to map columns of the DB onto elements in the UI.
SimpleCursorAdapter myCursorAdapter =
new SimpleCursorAdapter(
this, // Context
R.layout.frm_item, // Row layout template
cursor, //cursor record infomation
fromFieldNames, //DB column names where the infomation is coming from
to // and where the infomation is being sent to
);
myCursorAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
int nCheckedIndex = cursor.getColumnIndexOrThrow(DBAdapter.KEY_START);
if (columnIndex == nCheckedIndex) {
long DBStart = cursor.getLong(DBAdapter.COL_START); //Value is being passed correctly into here!!!!
TextView txtStart= (TextView) view;
txtStart.setText(DateFormat.format("h:mm a",DBStart )); // Not being sent as formatted data correctly here?????????????
}
return false;
}
});
ListView myList = (ListView) findViewById(R.id.listviewactions);
myList.setAdapter(myCursorAdapter);
}
期待您的回复
斯诺伊