我正努力解决一个问题。
我的Firestore文档设置如下:
在这种情况下,标题是地图。
每个地图都有不同的键名(nameOfHeading),但是每个文档都有“标题” 字段(地图)。
我想检索该地图并增加布局,但是我无法弄清楚如何检索地图对象。
我尝试通过以下代码获取它:
Map<String, String> map = klasa.getHeading();
for(Map.Entry<String, String> heading: map.entrySet()) {
View v = getLayoutInflater().inflate(R.layout.layout1, (ViewGroup)
findViewById(android.R.id.content), false);
TextView nameOfHeading = v.findViewById(R.id.text1);
nameOfHeading.setText(heading.getKey());
TextView dummyText = v.findViewById(R.id.text2);
dummyText.setText(heading.getValue());
linearLayout.addView(v);
}
我的类方法 getHeading()看起来像这样:
private Map<String, String> heading;
public Map<String, String> getHeading() {
return heading;
}
这段代码正在检索我 map 对象上的null。