use of com.google.firebase.database.DatabaseError in project SocialRec by Jkuras.
the class MainActivity method getPosts.
// sets listener at db/posts/deals/:all
// loads posts into mPosts, listener calls setUI
public void getPosts() {
mref = mDataBase.getReference("posts/deals");
ValueEventListener postListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// initialize array of all posts and add them to mPosts
mPosts = new ArrayList<DealPost>();
for (DataSnapshot child : dataSnapshot.getChildren()) {
mPosts.add((DealPost) child.getValue(DealPost.class));
}
setUI();
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
// ...
}
};
mref.addListenerForSingleValueEvent(postListener);
}
Aggregations