繁体   English   中英

如何将数据放入 Firestore 数据库集合中的 Arraylist 中?

[英]How to get data into an Arraylist in a collection in the Firestore Database?

我正在使用云 Firestore 数据库,我有一个名为 Jobpost1 的集合。 我想从这个集合中获取数据并存储在数组列表中。

我的Java代码

List<Jobpost> mList = new ArrayList<>();  //this is my arraylist
private CollectionReference collectionReference=db.collection("Job Post1");

 @Override
    public void onStart() {
        super.onStart();

        collectionReference.get()
                .addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
                    @Override
                    public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                        if (!queryDocumentSnapshots.isEmpty()){
                            for (QueryDocumentSnapshot journals: queryDocumentSnapshots){

                            }

                        }else {

                            noJournalEntry.setVisibility(View.VISIBLE);

                        }
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {

                    }
                });

    }

数据库

您可以通过这种方式填充列表

    List<Jobpost> mList = new ArrayList<>();  //this is my arraylist
    private CollectionReference collectionReference=db.collection("Job Post1");

    @Override
    public void onStart() {
        super.onStart();

        collectionReference.get()
                .addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
                    @Override
                    public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                        if (!queryDocumentSnapshots.isEmpty()){
                            for (QueryDocumentSnapshot journals: queryDocumentSnapshots){
                                 JobPost jobPost= journals.toObject(JobPost.class);
                                 mList.add(jobPost);
                            }
                        }else {
                            noJournalEntry.setVisibility(View.VISIBLE);
                        }
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {

                    }
                });

    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM