0
on android i have a cursor where it searches the data in the database and returns the data perfectly but..
as I insert a second cursor inside the first?
to pull data from a second table
my code
try {
StringBuilder sbQuery = new StringBuilder();
sbQuery.append("select * from contatos");
//
Cursor cursor = db.rawQuery(sbQuery.toString(), null);
//
while (cursor.moveToNext()) {
HMAux_Contatos hmAux = new HMAux_Contatos();
hmAux.put(
HMAux_Contatos.ID,
cursor.getString(cursor.getColumnIndex("id_contato")))
;
hmAux.put(
HMAux_Contatos.NOME,
cursor.getString(cursor.getColumnIndex("nome")))
;
StringBuilder sbQuery2 = new StringBuilder();
sbQuery.append("select * from contatos_numeros where id_contato = "+hmAux.get(HMAux_Contatos.ID)+" and principal = '1' ");
Cursor cursor2 = db.rawQuery(sbQuery2.toString(), null);
hmAux.put(
HMAux_Contatos.DESCRICAO,
cursor2.getString(cursor2.getColumnIndex("descricao")))
;
hmAux.put(
HMAux_Contatos.NUMERO,
cursor2.getString(cursor2.getColumnIndex("numero")))
;
cursor2.close();
cursor2 = null;
//
dados.add(hmAux);
}
cursor.close();
cursor = null;
} catch (Exception e) {
Log.d("#Erro Do Servidor", String.valueOf(e));
}
without the second cursor , it works perfect but it is obvious that the data is missing parts since the other data are in a second table
made perfect his example, it even helps to make the code cleaner, I managed to solve otherwise but a little more complicated, thanks for the help
– Jonnys J.