I’m binding data from a cursor to a list as shown below;
db.open();
Cursor c = db.getAllRowsCursor();
c.moveToFirst();
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
this, // Context.
R.layout.custom_row_view,
c,
new String[] {"name", "distance", "time"},
new int[] {R.id.text1, R.id.text2, R.id.text3});
setListAdapter(adapter);
db.close();
This works fine but it only shows the data. What is the best way to add headings to the data?
For example I want the list to read
Name: <name data>
Distance: <distance data>
Time: <time data>
rather than just;
<name data>
<distance data>
<time data>
I hope its clear what I’m trying to achieve here.
Thanks.
You can extend SimpleCursorAdapter and override method
bindView (View view, Context context, Cursor cursor)Here
view– is a yourR.layout.custom_row_view.Cursor – your cursor which already moved to correct position
You need manually get Strings from cursor, get TextViews from view, add headings and set correct text to TextViews