Modify cursor data before using SimpleCursorAdapter in ListView
On my android application, I have a table in the Sqlite database that
stores appointments. Each appointment has a StartDateTime column which
stores both the date and the time. In my application, these appointments
are queried and displayed in a ListView via a SimpleCursorAdapter.
SimpleCursorAdapter adapter;
private void populateListView() {
Cursor cursor = Db.Functions.getAppointmentList(); // Cursor
containing all appointments
String[] cols = new String[] { "Subject", "StartDateTime" };
int[] to = new int[] { R.id.lblSubject, R.id.lblTime };
adapter = new SimpleCursorAdapter(
this, R.layout.appointment_info, cursor, cols, to, 0);
ListView listView = (ListView) findViewById(R.id.lstAppts);
listView.setAdapter(adapter);
}
This currently just slaps whatever is in the StartDateTime column straight
into onto R.id.lblTime, however ideally I would like my listview to only
display the time but not the date. This is as far as my knowledge of the
matter goes, so would appreciate it if anyone could explain how I can
refine the cursor results before applying them to the listview. Many
thanks.
No comments:
Post a Comment