【发布时间】:2020-04-26 15:22:42
【问题描述】:
我正在尝试在单个文档中使用附加的图像数据结构填充 Android 中的 RecylerView。我想列出每个 ID 的每个名称、地区、图像。
它需要在不破坏子集合的情况下完成。是否有任何可能的智能方法来填充RecylerView。谢谢
这是我正在使用的示例数据。 [![在此处输入图片描述][1]][1]
编辑 1: 我尝试实现以下,它有效吗?
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
【问题讨论】:
-
到目前为止你尝试过什么?请同时添加您的数据库的另一个屏幕截图以查看您的根集合。
-
添加了屏幕截图。我只有一个根集合。但只是带有嵌套对象的文档。我要查询最底层的嵌套地图对象
-
很抱歉,我看到的截图和以前一样。可以查一下吗?
-
抱歉,拖错了图片。更新
标签: java android android-recyclerview google-cloud-firestore stickyrecycleview