I have a project in android, in which I have to insert records in an activity and show them in a recycler, when I insert the message it is shown that it was inserted correctly, I must show that data in a second activity, when doing the query if it finds the data but it brings them null and therefore shows the empty fields. Here I leave the code.
ActivityInsertar
llenardatos(){
conexion con;
con=new conexion(this);
con.open();
SQLiteDatabase bd = con.getWritableDatabase();
ContentValues registro = new ContentValues();
registro.put(utilidades.Titulo, _titulo.getText().toString());
registro.put(utilidades.Nombre, Nombre.getText().toString());
registro.put(utilidades.telefono, _telefono.getText().toString());
registro.put(utilidades.User_Add, idUser);
bd.insertOrThrow(utilidades.TablaPersonas, null, registro);
Toast.makeText(getBaseContext(), "Registro agregado", Toast.LENGTH_LONG).show();
onAgregarSuccess();
}
onAgregarSuccess(){
_btnAgregar.setEnabled(true);
Intent intent = new Intent(this, ActivityMostrar.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
}
ActivityShow
public boolean GetListGestiones() {
try {
tring query = "Select * from " + utilidades.TablaPersonas+ " where User_Add= '" + idUser +"'";
Cursor cursor = bd.rawQuery(query, null);
if (cursor.getCount() == 0) {
Toast.makeText(context, "No se encontraron datos", Toast.LENGTH_SHORT).show();
}
else if (cursor.getCount() >= 1) {
cursor.moveToFirst();
do {
entidades=new Entidades(entidades);
entidades.setTitulo(cursor.getString(cursor.getColumnIndex(utilidades.Titulo)));
entidades.setNombre(cursor.getString(cursor.getColumnIndex(utilidades.Nombre)));
entidades.setTelefono(cursor.getString(cursor.getColumnIndex(utilidades.Telefono)));
listtablapersonas.add(entidades);
} while (cursor.moveToNext());
}
cursor.close();
}
catch (Exception e) {
e.toString();
}
return true;
}