[英]How to store arraylist of objects in firebase database android
我有一個用於創建組的模型類
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 的新手。
你沒有那個arraylist的setter和getter..參考這個鏈接-Java 中ArrayList的Getter和Setter
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.