im using cloud firestore database and i have an collection which is named Jobpost1. i want to get data from this collection and store in arraylist.
my java code
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) {
}
});
}
You can populate list this way
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) {
}
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.