Metod像没有FirestoreRecyclerAdapter的getItemCount

时间:2018-12-05 00:25:29

标签: android firebase google-cloud-firestore firebaseui

我希望元素的可见性取决于Firestore数据库中列表元素的数量。不幸的是,如果不使用提供给我getItemCount方法的firestoreRecyclerAdapter,我将无法正确实现它。设置标志无效,因为onComplete方法在最后完成。我听说有.get (). Then (snap => {,收到消息“那么无法解析符号(?)”

这是我的代码

           userEmail = ((MainActivity) getActivity()).getUserEmail();
    FirebaseFirestore.getInstance().collection("goalsData").document(userEmail).collection("dailyGoals")
            .whereEqualTo("isDone", true)
            .get()
            .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                @Override
                public void onComplete(@NonNull Task<QuerySnapshot> task) {
                    List<GeneralGoalsModel> doneGoalsList = new ArrayList<>();
                    if (task.isSuccessful()) {
                        for (QueryDocumentSnapshot document : Objects.requireNonNull(task.getResult())) {
                            GeneralGoalsModel item = document.toObject(GeneralGoalsModel.class);
                            doneGoalsList.add(item);
                            count = true;
                        }
                        GeneralGoalsAdapter generalGoalsAdapter = new GeneralGoalsAdapter(getContext(), doneGoalsList);
                        goalsDoneListView.setAdapter(generalGoalsAdapter);
                    } else {
                        Log.d(TAG, "Error getting documents: ", task.getException());
                    }
                }
            });


    assert goalsDoneListView != null;
    if (progressBar != null) {
        progressBar.setVisibility(View.GONE);
    }
    if (count == false) {
        goalsDoneListView.setVisibility((View.GONE));
        emptyView.setVisibility((View.VISIBLE));
    } else {
        goalsDoneListView.setVisibility(View.VISIBLE);
        emptyView.setVisibility(View.GONE);
    }
}

0 个答案:

没有答案