Told Firebase Android [closed]

1

So I'm having a project here from an appblog,

Ineedhelpnowtogetthetanned.

mDatabaseLike=FirebaseDatabase.getInstance().getReference().child("Likes");


  }
        });

        viewHolder.mLikeBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                mProcessLike = true;


                    mDatabaseLike.addValueEventListener(new ValueEventListener() {
                        @Override
                        public void onDataChange(DataSnapshot dataSnapshot) {

                              if (mProcessLike ){

                                    if(dataSnapshot.child(post_key).hasChild(mAuth.getCurrentUser().getUid())){

                                        mDatabaseLike.child(post_key).child(mAuth.getCurrentUser().getUid()).removeValue();
                                        mProcessLike = false;
                                    } else {

                                         mDatabaseLike.child(post_key).child(mAuth.getCurrentUser().getUid()).setValue("RandomValue");
                                        mProcessLike = false;
                                    }

                        }}

                        @Override
                        public void onCancelled(DatabaseError databaseError) {

                        }
                    });

                }
        });

    }
};

link

RESOLVED

    mDatabaseLike.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            //Log.e(String.valueOf(dataSnapshot.child(post_key)),dataSnapshot.getChildrenCount() + "");

            for (DataSnapshot snap: dataSnapshot.getChildren()) {
                //Log.e(String.valueOf(snap.child(currentUserId).toString()),snap.getChildrenCount() + "");
                mCurtidas.setText(dataSnapshot.child(currentUserId).getChildrenCount() + "");

            }}
                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });
    
asked by anonymous 31.12.2016 / 17:07

1 answer

0

You must have a class, which encapsulates blog post content. Adds a variable, which counts the likes. It can be a list or an int itself. In the database listener, you capture the content you are in the database.

   // Read from the database
    myRef.addValueEventListener(new ValueEventListener() {
   @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
    // This method is called once with the initial value and again
    // whenever data at this location is updated.
    SuaClasse  class = dataSnapshot.getValue(SuaClass.class);

    }

    @Override
     public void onCancelled(DatabaseError error) {
    // Failed to read value
    Log.w(TAG, "Failed to read value.", error.toException());
   }
  });

link

    
02.01.2017 / 18:44