How to identify the values that Log.e brings on Android with Firebase

0

I have this structure in Firebase

And I'm calling the last three data with the name "dose" with this structure

 my.child("usuario").orderByKey().limitToLast(3).addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    for(DataSnapshot snapshot : dataSnapshot.getChildren()) {
                        usuario us =snapshot.getValue(usuario.class);

                        Log.e("Datos: " , "" + us.getDosis());
                    }


                }

in debug appear

E / Data :: 160 E / Data :: 12           130

but I need to identify them and compare them in an if and generate the result and show it on the screen. Someone knows how I could do them, Thanks.

    
asked by Julian 05.10.2018 в 02:29
source

1 answer

-1

What you can do is save that data in an ArrayList and then use it

    my.child("usuario").orderByKey().limitToLast(3).addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                          ArrayList<String> dosis = new ArrayList();
                        for(DataSnapshot snapshot : dataSnapshot.getChildren()) {
                            usuario us =snapshot.getValue(usuario.class);
                             dosis.add(us.getDosis());
                            Log.e("Datos: " , "" + us.getDosis());
                        }

                    //Despues accede a los datos del array
                     String valor1 = dosis.get(0);
                     String valor2 = dosis.get(1);
                     String valor3 = dosis.get(2);

                        //Parseamos los datos
                           int valorDosis1 = Integer.parseInt(valor1);
                           int valorDosis2 = Integer.parseInt(valor2);
                           int valorDosis3 = Integer.parseInt(valor3);

                       //Comparar el mayor de las 3 dosis

                         if(valorDosis1>valorDosis2 && valorDosis1>valorDosis3){
                           //valorDosis1 mayor
                       }else{
                           //valorDosis3 mayor
                        }if(valorDosis2 > valorDosis1 && valorDosis2 > valorDosis3){

                         //valorDosis2 mayor
                            }else{
                           //valorDosis3Mayor
                        }

                    }

With that you should work well and calculate the largest of 3 doses

    
answered by 05.10.2018 / 05:53
source