I want to extract database from Firebase. In for each loop, it shows me the description from database but after the for each loop when I check it again for that description, it shows me null and not only for description but for all other values also. Here is the code for extracting data from Firebase. It doesn't shows any kind of error. Help me.
public void getDatafromFirebase(){
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
DataSnapshot Videoreference = dataSnapshot.child("Videos");
for (DataSnapshot videoschild : Videoreference.getChildren()){
DataSnapshot description = videoschild.child("Description");
DataSnapshot duration = videoschild.child("Duration");
DataSnapshot title = videoschild.child("Title");
DataSnapshot thumbnail = videoschild.child("Thumbnail");
details.setDescription(String.valueOf(description.getValue()));
details.setDuration(String.valueOf(duration.getValue()));
details.setTitle(String.valueOf(title.getValue()));
details.setThumbnail(String.valueOf(thumbnail.getValue()));
Log.e("details",details.description);
list.add(details);
}
Log.e("Size",list.get(0).description);
adapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(getActivity(), databaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}