I have a ListView displaying rows from the database with a
SimpleCursorAdapter (like in the NotePad tutorials). Instead of
displaying raw database values, I needed to "format" the text in the
row to be human readable. I wasn't sure how to achieve this, but I
managed to find SimpleCursorAdapter.ViewBinder and made it work with
that.
Is this the best way to do this?
I only ask because I've only got a single TextView per row, but I'm
pulling data from multiple columns. Also, the From and To parameters
for constructing the SimpleCursorAdapter are pretty pointless with
this approach. So, I'm just ignoring the columnIndex passed to my
setViewValue() function and using cursor.getColumnIndexOrThrow to pull
the data from each column and build a string that I pass to the view.
Looking for any suggestions on how this might be improved.
adapter.setViewBinder(new ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int
columnIndex) {
String rowDesc = "";
int intValue = cursor.getInt(
cursor.getColumnIndexOrThrow("intColumn"));
rowDesc = "$" + intValue + " ";
switch (cursor.getInt(cursor.getColumnIndexOrThrow
("optionColumn")))
{
case 0:
rowDesc += "Option A";
break;
case 1:
rowDesc += "Option B";
break;
case 2:
rowDesc += "Option C";
break;
}
//etc etc
((TextView) view).setText(rowDesc);
return true;
}
});
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---