Firestore RecylerView没有连接适配器;跳过布局错误

时间:2019-02-20 09:56:54

标签: java android firebase android-recyclerview google-cloud-firestore

我有2个回收站视图,其中第一个视图工作正常,但在第二个视图中 我遇到错误:

  

未连接适配器;跳过布局

但是5分钟后,数据显示了。

我已经用谷歌搜索了,但没有得到任何结果。下面是我的代码。有人可以帮我吗?

公共类DashboardAdmin扩展了AppCompatActivity {

FirebaseFirestore database;
ProgressDialog mProgress;
ProgressBar progress_horizontal;

RecyclerView clmNameRecyclerView, visitCountRecyclerView;
ArrayList<User> clmNameArrayList;
ArrayList<DayCountGetterSetter> dayCountArrayList;
CLMNameRecyclerViewAdapter clmNameAdapter;
DayCountRecyclerViewAdapter dayCountRecyclerViewAdapter;   
LinearLayout clmNameRecyclerViewLayout, visitCountRecyclerViewLayout;
int listCount = 0;
int TestVariable = 0;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_dashboard_admin);

    progress_horizontal = findViewById(R.id.progress_horizontal);

    // Emp Name RecycleView
    clmNameRecyclerViewLayout = findViewById(R.id.clmNameRecyclerViewLayout);
    clmNameArrayList = new ArrayList<>();
    clmNameRecyclerView = findViewById(R.id.clmNameRecyclerView);
    clmNameRecyclerView.setHasFixedSize(true);
    clmNameRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    // Emp Name RecycleView

    // DayCount RecycleView
    visitCountRecyclerViewLayout = findViewById(R.id.visitCountRecyclerViewLayout);
    dayCountArrayList = new ArrayList<>();
    visitCountRecyclerView = findViewById(R.id.visitCountRecyclerView);
    visitCountRecyclerView.setHasFixedSize(true);
    visitCountRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    dayCountRecyclerViewAdapter = new DayCountRecyclerViewAdapter(DashboardAdmin.this, dayCountArrayList);
    visitCountRecyclerView.setAdapter(dayCountRecyclerViewAdapter);
    // DayCount RecycleView

    if (clmNameArrayList.size() > 0)
        clmNameArrayList.clear();

    mProgress = new ProgressDialog(this);
    mProgress.setMessage(" Please wait...");
    mProgress.setCancelable(false);
    mProgress.show();

    database = FirebaseFirestore.getInstance();
    database.collection("UsersCollection")
            .whereEqualTo("earuserReportingManager", currentUser)
            .whereEqualTo("earuserType", "User")
            .whereEqualTo("earuserStatus", "Active")
            .orderBy("name")
            .get()
            .addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
                @Override
                public void onSuccess(QuerySnapshot queryDocumentSnapshots) {

                    for (QueryDocumentSnapshot documentSnapshot : queryDocumentSnapshots) {
                        listCount = listCount + 1;
                        User user = documentSnapshot.toObject(User.class);
                        clmNameArrayList.add(user);
                    }
                    clmNameAdapter = new CLMNameRecyclerViewAdapter(DashboardAdmin.this, clmNameArrayList);
                    clmNameRecyclerView.setAdapter(clmNameAdapter);
                    mProgress.dismiss();
                    clmNameRecyclerView.smoothScrollToPosition(clmNameArrayList.size());

                    if (clmNameArrayList.size() == 0) {
                        Toast.makeText(DashboardAdmin.this, "Oops... No visits available", Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(DashboardAdmin.this, String.valueOf(clmNameArrayList.size()), Toast.LENGTH_SHORT).show();
                        progress_horizontal.setMax(clmNameArrayList.size());
                        progress_horizontal.setProgress(0);
                        progress_horizontal.setVisibility(View.VISIBLE);
                        GetDayCount();
                        mProgress.dismiss();
                    }
                }

                private void GetDayCount() {

                    while (TestVariable < clmNameArrayList.size()) {
                        userId = clmNameArrayList.get(TestVariable).getUserName();
                        ProcessFirebaseData();
                        TestVariable++;
                    }

                    dayCountRecyclerViewAdapter.notifyDataSetChanged();

                }

                private void ProcessFirebaseData() {

                    listCount = 0;
                    if (dayCountArrayList.size() > 0)
                        dayCountArrayList.clear();

                    database.collection("VisitReportCollection")
                            .whereEqualTo("userId", userId)
                            .orderBy("createdDate", Query.Direction.DESCENDING)
                            .get()
                            .addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
                                @Override
                                public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                                    for (QueryDocumentSnapshot documentSnapshot : queryDocumentSnapshots) {
                                        listCount = listCount + 1;
                                    }
                                    DayCountGetterSetter dayCountGetterSetter = new DayCountGetterSetter();
                                    dayCountGetterSetter.setDayCountMTD(listCount);
                                    dayCountGetterSetter.setDayCount1(listCount);
                                    dayCountGetterSetter.setDayCount2(listCount);
                                    dayCountGetterSetter.setDayCount3(listCount);
                                    dayCountGetterSetter.setDayCount4(listCount);
                                    dayCountGetterSetter.setDayCount5(listCount);
                                    dayCountGetterSetter.setDayCount6(listCount);
                                    dayCountGetterSetter.setDayCount7(listCount);
                                    dayCountArrayList.add(dayCountGetterSetter);
                                    progress_horizontal.setProgress(TestVariable);
                                }
                            })
                            .addOnFailureListener(new OnFailureListener() {
                                @Override
                                public void onFailure(@NonNull Exception e) {
                                    Log.d("FirebaseFailure", e.toString());
                                }
                            });
                }

            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.d("Dashboard", e.toString());
                }
            });

}

0 个答案:

没有答案