簡體   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