I’m new to Android. I’m trying to write a single method that would display 3 different columns from the same row of a database in 3 different textviews. Right now, I have 3 identical methods that each display a different column from the same row:
Display part of Method #1:
if (cursor != null){
cursor.moveToFirst();
result = result
+ cursor.getString(0);
return result;
}
return null;
Display part of Method #2:
if (cursor != null){
cursor.moveToFirst();
result = result
+ cursor.getString(1);
return result;
}
return null;
Display part of Method #3:
if (cursor != null){
cursor.moveToFirst();
result = result
+ cursor.getString(2);
return result;
}
return null;
So my question is: Is there a way to write a single method where the result would be something like “for a single DB row, cursor.getString(0); display in TextView #1, cursor.getString(1); display in TextView #2, cursor.getString(2); display in TextView #3?”
In case of Database Adapter, you can do one thing
In the calling activity you can set these returned array elements to textviews easily.
Hope this will help you.