I am trying to populate a RecylerView
in Android with attached image data structure in a single document. I want to list out each name, district, image for each ID.
It needs to be done without breaking down in the sub-collection. Is there any possible smart way to populate the RecylerView
. Thanks
Here is the sample data I am using. [![enter image description here][1]][1]
Edit 1: I tried to implement the following, does it work?
private void setUpRecyclerView(View view) {
CheckinList = new ArrayList<>();
notebookRef.get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>(){
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
for (QueryDocumentSnapshot documentSnapshot : queryDocumentSnapshots) {
user user = documentSnapshot.toObject(user.class);
HashMap<String, HashMap> about = user.getAbout();
for(Map.Entry<String, HashMap> entry : about.entrySet()) {
String key = entry.getKey();
HashMap<String, HashMap> value = entry.getValue();
String Name = "";
String District = "";
String imageUrl = "";
for (Map.Entry<String, HashMap> entry3 : value.entrySet()) {
String key3 = entry3.getKey();
if (key3 == "name"){
Name = entry3.getValue().toString();
} else if (key3 == "district"){
District = entry3.getValue().toString();
} else if (key3 == "imageurl") {
imageUrl = entry3.getValue().toString();
}
}
CheckinList.add(new Checkin(Name, District, imageUrl));
}
}
}
});
adapter = new NoteAdapter(CheckinList, mContext);
RecyclerView recyclerView = view.findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
recyclerView.setAdapter(adapter);
}```
full data scheme screenshot
[![enter image description here][2]][2]
[1]: https://i.stack.imgur.com/2Jspj.jpg
[2]: https://i.stack.imgur.com/iwsat.jpg