我试图从firebase获取值。在这里,我无法获取“考勤”节点中的值。查询Firebase,检索并传递给适配器
这里是我的模型:
public class MemberInGroup {
private String name;
private HashMap<String, HashMap<String, Object>> attendance;
private String group;
public MemberInGroup() {
}
public MemberInGroup(String name, HashMap<String, HashMap<String, Object>> attendance, String group) {
this.name = name;
this.attendance = attendance;
this.group = group;
}
public String getName() {
return name;
}
public String getGroup() {
return group;
}
public HashMap<String, HashMap<String, Object>> getAttendance() {
return attendance;
}
这里是在适配器populateView方法:
@Override
protected void populateView(View view, MemberInGroup member, int i) {
final String name = member.getName();
final String group = member.getGroup();
// Create views and assign values
final TextView nameTxtView = (TextView) view.findViewById(R.id.nameTxtView);
nameTxtView.setText(name);
HashMap<String, HashMap<String, Object>> attendance = member.getAttendance();
if(attendance != null) {
HashMap<String, Object> todayAttendance = attendance.get(Utility.getTodayName());
if(todayAttendance != null) {
String date = (String) todayAttendance.get("date");
}
}
我能够检索 “名” 和 “组”值,但不包括“考勤”内的日期散列图。 Utility.getTodayName给出正确的日期名称,但“日期”返回null。
这是我如何查询数据库并设置适配器:
final DatabaseReference ref = database.getReference();
Query query = ref.child("members")
.orderByChild("group")
.equalTo("group7");
// Set the adapter with groupMembersRef
MembersOfGroupAdapter mOfGroupAdapter = new MembersOfGroupAdapter(getActivity(), MemberInGroup.class,
R.layout.list_item_member_in_sport, query);
sportMembersListView.setAdapter(mOfGroupAdapter);
我想查询谁是某一组的所有成员。任何建议表示赞赏。
你说得对,那就是为什么日期是空的。如果我重新编码数据库,我将如何将结果传递给适配器?因为在populateView中我使用模型类来获得出席。是否有可能在populateView内创建一个新的查询? – fullMoon
以及如何得到()将被称为 – fullMoon
我已经添加了更多的答案,但是,是的,应该有可能在populateView方法中做另一个查询。当然,它在嵌套监听器的代码中看起来不太好 –