In the code below, I’m getting only the last row in my database, i.e. first name and last name of the last row in my DB. My question is: how do I change this code in order to get all the results printed?
package samples.directory;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class clanguage extends Activity {
protected Cursor c;
protected SQLiteDatabase db;
protected TextView employeeName;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webdesign);
WebView engine = (WebView) findViewById(R.id.web_engine);
db = (new DatabaseHelper(this)).getWritableDatabase();
Cursor c = db.rawQuery("SELECT firstName, lastName FROM employee", null);
if (c != null ) {
if (c.moveToFirst()) {
do {
String firstName= c.getString(c.getColumnIndex("firstName"));
String lastName = c.getString(c.getColumnIndex("lastName "));
String data = "<html>" +
"<body><table border=2> <tr> <td>"+firstName+"</td>+
<td>"+lastName+"</td></tr></body></html>";
engine.loadData(data, "text/html", "UTF-8");
}while (c.moveToNext());
}
}
}
try this way
you everytime override content of data object and load it.