How can i retrieve all the childs from "compresor_1" for example?
Firebase database:
"CompresoresEstandar" : {
"Compresor_1" : {
"Marca" : "SANDEN",
"Modelo" : "505/5H09",
"Canales" : "PV5",
"Dimametro-MM" : "120",
"Voltios" : "12",
"Conexion" : "V-O",
},
"Compresor_2" : {
"Marca" : "SANDEN",
"Modelo" : "505/5H09",
"Canales" : "PV5",
"Dimametro-MM" : "120",
"Voltios" : "12",
"Conexion" : "V-O",
},
Tried this example from the net but it shows me this error:
com.google.firebase.database.DatabaseException: Class java.util.Map has generic type parameters, please use GenericTypeIndicator instead
UPDATE 1
Tried already this:
GenericTypeIndicator<Map<String, String>> genericTypeIndicator = new GenericTypeIndicator<Map<String, String>>() {};
Map<String, String> map = dataSnapshot.getValue(genericTypeIndicator );
And this:
Map<String,String> map = dataSnapshot.getValue(Map.class);
With the same error.
UPDATE 3
Datasnapshot contains this information, how can i "divide each object?" .get("modelo") retrieve the first element with that key.
DataSnapshot { key = CompresoresEstandar, value = {Compresor_2={Letras Culata=, Voltios=12, Marca=SANDEN, Conexion=V-R, Canales=2A, RefACR=130002, Modelo=505/5H09, Dimametro-MM=125}, Compresor_3={Letras Culata=, Voltios=12, Marca=SANDEN, Conexion=V-C, Canales=2A, RefACR=130003, Modelo=505/5H09, Dimametro-MM=125}, Compresor_1={Letras Culata=, Voltios=12, Marca=SANDEN, Conexion=V-O, Canales=PV5, RefACR=130001, Modelo=505/5H09, Dimametro-MM=120}} }
WORKING CODE
@Override
public void onStart(){
super.onStart();
final FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference compresoresRef = database.getReference("CompresoresEstandar");
compresoresRef.orderByChild("Ref").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
dataSnapshot.getChildren();
CompresorModel coe = dataSnapshot.getValue(CompresorModel.class);
String modelo = coe.getModelo();
String marca = coe.getMarca();
String canales = coe.getCanales();
textData1.setText(modelo);
textData2.setText(marca);
textData3.setText(canales);
}