0
I can’t return the value inside my Arry always returns 0
Read
public class Read {
public ArrayList<RespostasAguaCasa> getLista() {
SQLiteDatabase db = Maindb.getInstancia().getReadableDatabase();
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();
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;
}
Update
public class Update {
SQLiteDatabase db = Maindb.getInstancia().getWritableDatabase();
SQLiteDatabase dbb = Maindb.getInstancia().getWritableDatabase();
SQLiteDatabase dbbb = Maindb.getInstancia().getWritableDatabase();
public boolean addResposta(RespostasAguaCasa respostasAguaCasa){
ContentValues cv = new ContentValues();
cv.put("id" , respostasAguaCasa.getId());
cv.put("valoragua" , respostasAguaCasa.getValoragua());
cv.put("acordarhora" , respostasAguaCasa.getAcordarhora());
cv.put("dormirhora" , respostasAguaCasa.getDormirhora());
cv.put("terceirahora" , respostasAguaCasa.getTerceirahora());
cv.put("quartahora" , respostasAguaCasa.getQuartahora());
cv.put("quintahora" , respostasAguaCasa.getQuintahora());
cv.put("acordarminutos" , respostasAguaCasa.getAcordarminu());
cv.put("dormirminutos" , respostasAguaCasa.getDormirminu());
cv.put("terceiraminutos" , respostasAguaCasa.getTerceiraminu());
cv.put("quartaminutos" , respostasAguaCasa.getQuartaminu());
cv.put("quintaminutos" , respostasAguaCasa.getQuintaminu());
return db.insert(Maindb.TABELA, null , cv)!= -1;
}
Methods I’m adding and searching
private void adicionarPessoa() {
RespostasAguaCasa p = new RespostasAguaCasa();
p.setId(1);
p.setValoragua(QuintaperguntaAguaCasa.valoragua);
p.setAcordarhora(EscolhaAguaCasa.hourx);
p.setAcordarminu(EscolhaAguaCasa.minutex);
p.setDormirhora(SegundaperguntaAguaCasa.hourxx);
p.setDormirminu(SegundaperguntaAguaCasa.minutexx);
p.setTerceirahora(TerceiraperguntaAguaCasa.hourxxx);
p.setTerceiraminu(TerceiraperguntaAguaCasa.minutexxx);
p.setQuartahora(QuartaperguntaAguaCasa.hourxxxx);
p.setQuartaminu(QuartaperguntaAguaCasa.minutexxxx);
p.setQuintahora(QuintaperguntaAguaCasa.hourxxxxx);
p.setQuintaminu(QuintaperguntaAguaCasa.minutexxxxx);
if (new Update().addResposta(p)) {
Toast.makeText(this, "Inserido com sucesso!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Erro ao inserir pessoa", Toast.LENGTH_SHORT).show();
}
}
private void verPessoas() {
ArrayList<RespostasAguaCasa> pessoas = new Read().getLista();
for (int i = 0; i < pessoas.size(); i++) {
RespostasAguaCasa p = pessoas.get(i);
Toast.makeText(this, "gg" + p.getId(), Toast.LENGTH_SHORT).show();
}
}}
Maindb
public class Maindb extends SQLiteOpenHelper{
public static final String DATABASE = "Projeto";
public static final int VERSION = 1;
public static final String TABELA = "Aguacasa";
private static Maindb instancia;
public static Maindb getInstancia() {
if (instancia == null) instancia = new Maindb();
return instancia;
}
private Maindb() {
super(Myapp.getContext(), DATABASE, null, VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
@Override
public synchronized void close() {
instancia = null;
super.close();
}
}
If you need any other information just ask .
It’s not the same code ?
– aleander rayson
no, it is not @aleanderrayson, there is no native ". getInstance" method, or Voce uses ". getInstance" or Voce reimplements the method to match your ". getInstance" that does not exist
– Armando Marques Sobrinho
this content comes from my maindb I will put it in the question
– aleander rayson