I’m currently displaying a heading name and description text in two separate TextViews from one table in a database in a single activity. I’m also using two queries to return the string for both heading and description as shown in the code below.
Is there a better way of doing this, I think I can return both heading and description from a single query but I’m unsure how to display it.
Calling code:
beachName = dbBeachHelper.getBeachName(passedVar);
beachText = dbBeachHelper.getBeachText(passedVar);
Queries:
public String getBeachName(String id) {
String[] args = {id};
Cursor c = getReadableDatabase().rawQuery("SELECT _id, BeachName FROM Beach WHERE _id=?", args);
if(c.moveToNext()){
return(c.getString(c.getColumnIndex("BeachName")));
}
c.close();
return id;
}
public String getBeachText(String id) {
String[] args = {id};
Cursor c = getReadableDatabase().rawQuery("SELECT _id, BeachText FROM Beach WHERE _id=?", args);
if(c.moveToNext()){
return(c.getString(c.getColumnIndex("BeachText")));
}
c.close();
return id;
}
Any help would be greatly appreciated.
Cheers,
Mike.
Updated
I would like to return a cursor but as I said above I don’t know what to do with it when I get it back. How do I separate the cursor into two variables that I can then use to fill the TextViews???
I would insist better to return the Cursor instead of String,
Then you can get the values from the Cursor.
UPDATE