Count++ doesn't work because its inner class, how can I solve this problem?

Viewed 12

If I put the count outside the method, it variable turns purple and I cant change it

public void signUp(View v) {

int count;

    String emailString = emailField.getText().toString();
    String passwordString = passwordField.getText().toString();
    String nameString = nameField.getText().toString();

    firestore.collection("item")
            .get()
            .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                @Override
                public void onComplete(@NonNull Task<QuerySnapshot> task) {
                    if (task.isSuccessful()) {

                        for (QueryDocumentSnapshot document : task.getResult()) {
                            items.add(document.toObject(Item.class));
                        }

                        for (Item item : items) {
                            String own = item.getOwner();
                            owners.add(own);
                        }

loop for (int i = 0; i < owners.size(); i++) {

                            firestore.collection("user").document(owners.get(i)).addSnapshotListener(new EventListener<DocumentSnapshot>() {
                                @Override
                                public void onEvent(@Nullable DocumentSnapshot value, @Nullable FirebaseFirestoreException error) {

I want to count++ everytime the userType is Admin String userType = value.getString("userType");

                                    if (userType.equals("Admin")) {
                                        count++;
                                    }


                                }
                            });


                        }


                    }

                }

            });
0 Answers
Related