Firebase does not recognize values

1

I've been with this problem for days, I hope you can help me:)

I have a code in Android Studio where I connect to Firebase, in which I upload values, modify and bring them. I have tried my application and it works well for some values, then for another value it does not work and then for other values yes, and so on. I do not understand why that would happen if the code is the same for all values. I leave here the code for your visualization, thanks:)

The methods to collect () and recover () are methods where I assign to an ArrayList the numbers 1 and 0 depending on whether a number of Radio Buttons were pressed, 1 is if the Radio button is pressed and the 0 is if it is not pressed.

 public void metodo_subir(View v) {

    recolectar();// recolecta los numeros delos RadioButtons
    codigoos=ArrayPostvaciado.toString();
    mRootReference.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                String todo = dataSnapshot.getValue().toString();
                if (todo.contains("LiberaPostvaciado")) {
                    if (todo.contains(ubicacion)) {
                        if (todo.contains(elemento)) {
                            p = 1;
                        }
                    }
                } else {
                    p = 0;
                }
            }
            if (p == 0) {
                subir(codigoos);
            } else if (p == 1) {
                modificaar(codigoos);
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {
        }
    });

}
public void subir(String codigoos){

    Map<String, Object> datosLibPostvaciado = new HashMap<>();
    datosLibPostvaciado.put("Elemento", elemento);
    datosLibPostvaciado.put("Procedimiento", procedimiento);
    datosLibPostvaciado.put("Ubicacion", ubicacion);
    datosLibPostvaciado.put("Codigo", codigoos);
    mRootReference.child("LiberaPostvaciado").push().setValue(datosLibPostvaciado);
}
public void modificaar(String codigoos) {
    final String codigoooos=codigoos;
    Query q = FirebaseDatabase.getInstance().getReference("LiberaPostvaciado").orderByChild("Elemento").equalTo(elemento);
    q.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                //if el recorrido contiene a la ubicacion cojo ese key y en ese key cambio el status
                String recorrido = snapshot.getValue().toString();
                if (recorrido.contains(ubicacion)) {
                    klave = snapshot.getKey();
                }
                FirebaseDatabase.getInstance().getReference("LiberaPostvaciado").child(klave).child("Codigo").setValue(codigoooos);

            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {
        }
    });
}

Here is the method where I bring the data from the Firebase

public void metodo_cargar_data(View v){  //METODO DONDE TRAIGO LOS DATOS DESDE EL FIREBASE

    mRootReference.child("LiberaPostvaciado").addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                String todo = snapshot.getValue().toString();
                if (todo.contains(elemento)){
                    if (todo.contains(ubicacion)){
                        PojoLibVaciado pojo = snapshot.getValue(PojoLibVaciado.class);
                        String codiggos=pojo.getCodigo();
                        recuperar(codiggos);
                    }
                }
            }}
        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {
        }
    });

}

This is how the Firebase is displayed:

    
asked by user110607 15.12.2018 в 03:43
source

0 answers