I have a database in an app in which I have registered the Names (VARCHAR) and an RFC (VARCHAR) of users. I have to do a search by entering a parameter in the two tables (Name and RFC), if there are repeated records, the list has to display all the records equal to the parameter that I insert. But my code only shows the first record that is equal to the parameter.
private void consultarSql() {
SQLiteDatabase db=conn.getReadableDatabase();
String[] parametros={campoId.getText().toString() , campoId.getText().toString() };
Usuario usuario=null;
try {
Cursor cursor=db.rawQuery("SELECT "
+Utilidades.CAMPO_ID+","
+Utilidades.CAMPO_NOMBRE+","
+Utilidades.CAMPO_TELEFONO+ ","
+Utilidades.CAMPO_RFC+ ","
+Utilidades.CAMPO_DIRECCION+","
+Utilidades.CAMPO_PASSWORD+
" FROM "+Utilidades.TABLA_USUARIO+" WHERE "+Utilidades.CAMPO_RFC+ " = ? OR " +Utilidades.CAMPO_NOMBRE+" = ? ",parametros);
cursor.moveToFirst();
usuario = new Usuario();
usuario.setId(cursor.getInt(0));
usuario.setNombre(cursor.getString(1));
usuario.setTelefono(cursor.getString(2));
usuario.setRFC(cursor.getString(3));
usuario.setDireccion(cursor.getString(4));
usuario.setPassword(cursor.getString(5));
//System.out.println("Usuario encontrado con nombre: "+ usuario.getNombre());
listaUsuario.add(usuario);
}catch (Exception e){
e.printStackTrace();
Toast.makeText(getApplicationContext(),"No se encontro",Toast.LENGTH_LONG).show();
}
}