collect firebase data by means of equals

0

I'm having trouble picking up data that apparently did not have any complications, the question is I want to collect the Yes and No of the objects I get and I'm not able to

I leave the code

  database.getReference("Events").child( code ).child( "Users" ).addValueEventListener( new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            int cont = 0; int si=0; int no=0; int mb=0;
          //  String Si="Si",No="No";
            String hola;
            for (DataSnapshot snapshot: dataSnapshot.getChildren()){

                User user = snapshot.getValue(User.class);
                data.add( user);
                hola = data.get( 0 ).getvote();

                if(hola.equals( "Si" )){
                    si++;
                }

                if (hola.equals( "No" )){
                    no++;
                }

                if(hola.equals( null )){
                    mb++;
                }
                cont++;
            }
            participantes = data.size();// Total participantes
            String participantesCast= Integer.toString( participantes );
            tvTotalParticipantes.setText( participantesCast );
            Log.i("Si","Si"+si);
            Log.i("No","No"+no);
            Log.i("mb","mb"+mb);
           /// Log.i("mb","mb"+hola);

        }

In the debug everything goes to the Si and the Mb and I do not understand what I'm doing wrong because I've tried it in several ways without coming up with the good one

I add User class     public class User {

private String name;
private String email;
private String avatar;
private List<String> events;
private String vote;
    
asked by lujan 09.08.2018 в 18:21
source

1 answer

1

You're always getting the same value by doing .get(0) in the list data . It is not necessary to obtain the value of the list when you directly have the reference of the object in user . Try to do:

String hola = user.getVote();

if(hola == null)
   mb++;
else if(hola.toLowerCase().Equals("si"))
   si++;
else if(hola.toLowerCase().Equals("no"))
   no++;
    
answered by 10.08.2018 / 01:25
source