I'm using a Firebase database to store and read a list of "clubs" in an Android app. Below there's the Json representation of that.
{
"clubs" : [ {
"id" : 1,
"image" : {
"allocationByteCount" : 589824,
"byteCount" : 589824,
"config" : "ARGB_8888",
"density" : 320,
"generationId" : 212,
"height" : 384,
"mutable" : false,
"premultiplied" : true,
"recycled" : false,
"rowBytes" : 1536,
"width" : 384
},
"name" : "Axis"
}, {
"id" : 2,
"image" : {
"allocationByteCount" : 589824,
"byteCount" : 589824,
"config" : "ARGB_8888",
"density" : 320,
"generationId" : 214,
"height" : 384,
"mutable" : false,
"premultiplied" : true,
"recycled" : false,
"rowBytes" : 1536,
"width" : 384
},
"name" : "Allies"
}, {
"id" : 3,
"image" : {
"allocationByteCount" : 589824,
"byteCount" : 589824,
"config" : "ARGB_8888",
"density" : 320,
"generationId" : 216,
"height" : 384,
"mutable" : false,
"premultiplied" : true,
"recycled" : false,
"rowBytes" : 1536,
"width" : 384
},
"name" : "Neutrals"
} ]
}
I'm using a FirebaseAdapter class to call methods upon the Firebase database. But it returns null when trying to get all clubs.
Bellow theres the method that calls it:
public List<BDClub> getClubs() {
list.clear();
database.getReference("clubs").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()){
System.out.println(dataSnapshot.getChildrenCount());
for(DataSnapshot array : dataSnapshot.getChildren()){
clubs = array.getValue(BDClub[].class);
for(BDClub c : clubs){
list.add(c);
}
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
return list;
}
Is there a way to retrieve a list of clubs? Thanks in advance.