Search in sources :

Example 61 with DatabaseError

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);
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Aggregations

DatabaseError (com.google.firebase.database.DatabaseError)61 DataSnapshot (com.google.firebase.database.DataSnapshot)59 ValueEventListener (com.google.firebase.database.ValueEventListener)44 DatabaseReference (com.google.firebase.database.DatabaseReference)22 View (android.view.View)21 Intent (android.content.Intent)15 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)13 RecyclerView (android.support.v7.widget.RecyclerView)13 User (com.polito.mad17.madmax.entities.User)12 MutableData (com.google.firebase.database.MutableData)11 Transaction (com.google.firebase.database.Transaction)11 Bundle (android.os.Bundle)10 TextView (android.widget.TextView)9 ChatMessageHelper (ingage.ingage20.helpers.ChatMessageHelper)8 ImageView (android.widget.ImageView)6 SimpleDateFormat (java.text.SimpleDateFormat)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ChildEventListener (com.google.firebase.database.ChildEventListener)5 Event (com.polito.mad17.madmax.entities.Event)5