compare saved data in Android Studio Firebase

0

I have the structure corresponding to the data stored in Firebase Database via android

I want to obtain the data indicated in red the last 2 or 3 "doses" saved.

I have this structure but I do not know if it is the correct one to obtain the data and compare which one was the largest using if () {} and show the result on the screen.

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);
                        //textViewcalculo.setText(us.getDosis());
                        Log.e("Datos: " , "" + us.getDosis());
                    }

                }

The code frangment extracts the information but I do not know how to identify it and obtain it to compare

the debug shows the last three, but it does not help me to compare them so someone knows how I can do it ?? thanks

    
asked by Julian 05.10.2018 в 04:43
source

1 answer

1

would be like this.

my.child("usuario").orderByKey().limitToLast(3).addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                Usuario usuario;
                for(DataSnapshot snapshot : dataSnapshot.getChildren()) {
                    Usuario us=snapshot.getValue(Usuario.class);
                    if(usuario==null || usuario.getDosis()< us.getDosis()){
                       usuario = us;
                    }
                }
                Log.e("La mayor dosis es esta: " + usuario.getDosis());
            }

Greetings.

    
answered by 13.10.2018 в 05:38