项目未追加到OnSnapShotListener

时间:2019-07-03 17:17:36

标签: java android firebase

我正在尝试在Firestore数据库上运行查询,并使用onSnapShotListener检查实时更新。但是在侦听器中,当我附加从方法中获取的值时,不会附加这些值,并且ArrayList保持为空。这里的数据是我从意图中得到的投资组合。并将值完美分配给变量数据。

        switch (view.getId()){
            case R.id.highestDegree:
                showDialogClick(studyList,"Choose Highest Degree",highestDegreeBtn);
                break;
            case R.id.fieldOfStudy:
                showDialogClick(fieldOfStudyList,"Choose One",fieldOfStudyBtn);
                break;
            case R.id.personalDetails:
                if(data != null){
                    Bundle bundle = new Bundle();
                    bundle.putString("template_id",data);
                    bundle.putString("fieldOfStudy",fieldOfStudyBtn.getText().toString());
                    bundle.putString("highestDegree",highestDegreeBtn.getText().toString());
                    Intent intent = new Intent(DataEntry.this,PersonalInfo.class);
                    intent.putExtras(bundle);
                    startActivity(intent);
                }else{
                    Intent finalIntent = new Intent(DataEntry.this,PersonalInfo.class);
                    finalIntent.putExtra("template_id",dataFromEdu);
                    startActivity(finalIntent);
                }
                break;


            case R.id.educationDetails:
                getData();
                Toast.makeText(DataEntry.this, eduData.toString(), Toast.LENGTH_SHORT).show();
                    if(data != null){
                        Bundle bundleEduc = new Bundle();
                        bundleEduc.putString("template_id",data);
                        Intent intentEduc = new Intent(DataEntry.this,EducationInfo.class);
                        intentEduc.putExtras(bundleEduc);
                        startActivity(intentEduc);
                    }else{
                        Intent finalIntent = new Intent(DataEntry.this,EducationInfo.class);
                        finalIntent.putExtra("template_id",dataFromEdu);
                        startActivity(finalIntent);

                    }

                break;


                }







        }


        public ArrayList<String> getData(){
            String checkId;
            if(data != null){
                    checkId = data;
            }else {
                    checkId = dataFromEdu;
            }


                Query query = education.whereEqualTo("portfolioid",checkId);

                query.addSnapshotListener(this,new EventListener<QuerySnapshot>() {
                    @Override
                    public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
                        if(e != null){
                            Log.i("Error",e.toString());
                            return;
                        }else{
                            for (QueryDocumentSnapshot q : queryDocumentSnapshots){
                                    eduData.add(q.getString("schoolName"));
                            }
                        }
                    }
                });


                return eduData;
        }
    }```







0 个答案:

没有答案