Using Select android studio

0

I was able to save information to my SQLite database, but I can not call them.

I'm trying using 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;

}

}

    
asked by anonymous 13.06.2018 / 19:36

1 answer

0

I took a look at your code and noticed that in the Read () class, when you do the return list; , you are returning the newly created empty list is assigning the query result to it.

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

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

I hope to have helped, hug.

    
14.06.2018 / 00:45