Using Select android studio

Asked

Viewed 327 times

0

I was able to save information in my Sqlite bank, only I can’t call them.

I’m trying to use the following method:

  private void verPessoas() {
   ArrayList<RespostasAguaCasa> pessoas = new Read().getLista();
   for (int i = 0; i < pessoas.size(); i++) {
    RespostasAguaCasa p = pessoas.get(i);
    int a = p.getValoragua();
    impri.setText("+"+ a);
}

if (pessoas.size() == 0) System.out.println("# Não existe valor .");

}

READ

  public class Read {
        public ArrayList<RespostasAguaCasa> getLista() {
        SQLiteDatabase db = 
      Maindb.getInstancia().getWritableDatabase();
        String query = "SELECT * FROM " + Maindb.TABELA;
        ArrayList<RespostasAguaCasa> lista = new ArrayList<>();

        Cursor c = db.rawQuery(query, null);
        if (c.moveToFirst()) {

            do {
                RespostasAguaCasa resp = new 
               RespostasAguaCasa(c.getString(0));
                resp.setId(c.getInt(1));
                resp.setValoragua(c.getInt(2));
                resp.setAcordarhora(c.getInt(3));
                resp.setAcordarminu(c.getInt(4));
                resp.setDormirhora(c.getInt(5));
                resp.setDormirminu(c.getInt(6));
                lista.add(resp);
            }
            while (c.moveToNext());
            {
            }


}
c.close();
return lista;

}

}

1 answer

0


I took a look at your code and realized that in class Read(), when you do the re-turn list;, you are returning the newly created empty list and are not assigning the result of query to her.

 ArrayList<RespostasAguaCasa> lista = new ArrayList<>();
 return lista;

I also recommend taking a look at the data persistence libraries Room and Realm. They are simpler to implement, but with a power greater or equal to the "raw" persistence method. Here is another sample I have using the Room, here is the link: Sample Room.

I hope I helped, hug.

  • I took a look it helped me really thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.