gpt4 book ai didi

java - 如何在firebase数据库android中存储对象的数组列表

转载 作者:行者123 更新时间:2023-12-01 19:34:18 27 4
gpt4 key购买 nike

我有一个模型类,我用它来创建组

public class GroupModel {
String groupId, groupName;
ArrayList<GroupMember> groupMembersList;

public GroupModel(String groupId, String groupName, ArrayList<GroupMember> groupMembersList) {
this.groupId = groupId;
this.groupName = groupName;
this.groupMembersList = groupMembersList;
}

public String getGroupId() {
return groupId;
}

public void setGroupId(String groupId) {
this.groupId = groupId;
}

public String getGroupName() {
return groupName;
}

public void setGroupName(String groupName) {
this.groupName = groupName;
}
}

当我使用此模型存储数据时,除了 groupMembersList 之外的所有数据都已存储,我不知道为什么。我使用以下方法来存储组数据

mdDatabaseReference
.child(getResources().getString(R.string.group_list_child_key))
.setValue(groupModel).addOnCompleteListener(task -> {//multiple informations in with same user(instertion will add new information)
{
if (task.isSuccessful()) {
Toast.makeText(this, "Group Created", Toast.LENGTH_SHORT).show();
Utils.hideProgress();
} else {
Toast.makeText(this, task.getException().toString(), Toast.LENGTH_LONG).show();
Utils.hideProgress();
}
}
});

其中groupModel是上面给定的GroupModel类的对象。

请建议我,因为我是 firebase 新手。

最佳答案

你没有该数组列表的 setter 和 getter..请参阅此链接 - Getters and Setters for ArrayLists in Java

关于java - 如何在firebase数据库android中存储对象的数组列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59235197/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com