I use the below code to fetch a particular record from sqlite.
public String getDetails(long phone) throws SQLException{
Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] {NAME, AGE, AREA, PHONE, SEX}, PHONE + "=" + phone, null, null, null, null, null);
if(mCursor != null){
mCursor.moveToFirst();
}
String result = mCursor.getString(mCursor.getColumnIndex(NAME));
return result;
}
And I am calling this method from another class with the below code
dbAdapterExisting.read();
String temp = dbAdapterExisting.getDetails(mobile);
dbAdapterExisting.close();
textViewExistingName.setText(temp);
The record is getting fetched and am able to display the ‘name’ field in textview, but how do i fetch all the fields i.e ‘age’, ‘area’, ‘sex’ and show it on different textviews.
Since your
getDetails()method only returns a single string, and you want to fetch multiple items, you need to change some things.Mapsare good data structures for returning data this way. For example:}
Then, in your calling code switch to using the Map returned instead: