I add items to a list through a Model class and then add these items to an ArrayList<Object>
. However, I always get a size of zero even if the commentsList.size() > 1
.
I tried to convert the List
to ArrayList
and tried adding items. But always the size was 0 on ArrayList<Object>
.
ArrayList<Comments> commentsList = new ArrayList<>(Arrays.asList(new Comments("username", "time", "date")));
Here are the functions that I am using.
private ArrayList<Object> getObject() {
if (getComments() != null && getComments().size()>=1) {
objects.add(getComments().get(0));
}
return objects;
}
public static ArrayList<Comments> getComments() {
ArrayList<Comments> commentsList = new ArrayList<>();
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Comments");
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
commentsList.clear();
for (DataSnapshot shot : snapshot1.getChildren()) {
Comments comments = shot.getValue(Comments.class);
commentsList.add(comments);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return commentsList;
}