How do I get data that does not repeat from Firebase in Android Studio?


Hi, I have a problem with Firebase, I'm creating an app that is like a data capture application where the user clicks on YES or NO and I have to make a statistical chart of how many of them have SI in different fields such as Comment, Plane ,etc. but since the user can edit some fields within the package (for example, edit the "Comment" field to a "NO"), another package of C1 code would be created with a "NO" in "comment" but the previous package would still be had the "Yes" in his "comment" and I at the time of doing the statistical graph would have to use the last value entered and then the Firebase read me all data regardless of whether it is repeated or not and would give me wrong data

I made a for cycle so I could go through all the fields but I do not know how to remove the repeated ones. Thank you

Query query = FirebaseDatabase.getInstance().getReference("Usuario").orderByChild("Comentario").equalTo("Si");
            query.addListenerForSingleValueEvent(new ValueEventListener() {
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                    cnt = 0;
                    for (DataSnapshot snapshot : dataSnapshot.getChildren()) {

                        String value = snapshot.getValue().toString();
                        if (value.contains("Codigo=C")) {
                        if (value.contains("Codigo=V")) {
                        if (value.contains("Codigo=P")) {

                    Intent intento = new Intent(getApplicationContext(), DataGraficos.class);
                    intento.putExtra("NcomentCol", NcomentariosCol);



                public void onCancelled(@NonNull DatabaseError databaseError) {
asked by Pedro N. 11.11.2018 в 22:02

2 answers


At the time of doing the statistical graph, I would have to use the   last value entered and then the Firebase read me all the data without   import if it is repeated or not and give me wrong data

Probably adding to your query that brings you only the last element added

Query query = FirebaseDatabase.getInstance().getReference("Usuario").orderByChild("Comentario").equalTo("Si").limitToLast(1);
answered by 13.11.2018 в 21:17

"would create another package of code C1 with a" NO "in" comment "but would still be the previous package that had the" Yes "in his" comment "and I at the time of making the statistical graph would have to use the last value entered "

If you do not want to use the previous "package" to save it? Do you use it at another time? Can not you simply update the "yes" to a "no" instead of creating another entry?

Another thing I do not understand is why all those entries are in the "user" node, do you have the same for each user? all those entries are from the same user?

There, leaving an example of what results you would like to obtain, can help you. Regards!

answered by 14.11.2018 в 19:37