I am trying to get data from SQLite database in android, but having some trouble to get the data. Can someone please help me out? Log statement inside function getAppCategoryDetail prints correct value but log statement where I call the function doesn't print. I am not able to print the line called after the function i.e. End Function and the value of name. I have one class called parent record that contains 6 column and multiple rows when I am trying to call the function not getting the values :-
Here is my DBHandler code :-
public String getAppCategoryDetail() {
String selectQuery = "SELECT * FROM " + TABLE_PARENT;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
String[] data = new String[cursor.getCount()];
String name, format, exp_date, time;
int count = 0;
if (cursor.moveToFirst()) {
do {
// get the data into array, or class variable
Log.e("print here",cursor.getString(1));
data[count] = cursor.getString(1);
Log.e("Print here also",data[count]);
count++;
} while (cursor.moveToNext());
}
cursor.close();
return data[0];
}
Button btn = (Button) findViewById(R.id.submitButton3);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.e("Start Function", "to get the values");
addButtonClicked();
String name = dbHandler.getAppCategoryDetail();
Log.e("End Function",name);
}
});
Aucun commentaire:
Enregistrer un commentaire