mercredi 9 décembre 2015

Why is the code not viewing database content in SQLite android?

When i add records to the database and try to display it the display button doesn't work i set an action listener to it still it doesn't pop up or show any details.

Database handler code //assuming there's a table called appointments

  public Cursor getAllData (){
    SQLiteDatabase db = getWritableDatabase();
    Cursor res = db.rawQuery("SELECT * FROM " + TABLE_APPOINTMENTS,null);
    return res;
}

JAVA code

 public void viewAll (){
    viewallbut.setOnClickListener(
            new View.OnClickListener() {
        @Override
        public void onClick (View v){
            Cursor res = dbh.getAllData();
            if(res.getCount()==0){
                showMessage("Error","Nothing to display");
                return ;
            }

            StringBuffer sb = new StringBuffer();
            while(res.moveToNext()){
                sb.append("Date: " +res.getString(0)+"\n");
                sb.append("Appointment: " +res.getString(1)+"\n");
                sb.append("\nLocation: " +res.getString(2)+"\n");
                sb.append("\nPriority: " +res.getString(3)+"\n");
                sb.append("\nStatus: " + res.getString(4)+"\n\n");
            }

            showMessage("Data",sb.toString());
        }

    }
    );
}

public void showMessage (String title, String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setCancelable(true);
    builder.setTitle(title);
    builder.setMessage(message);
}

The dialog does not pop up even

Aucun commentaire:

Enregistrer un commentaire