1
So I’m with a project here from an appblog,
I need help now so I can count the likes.
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) {
}
});
}
});
}
};
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) {
}
});
What a problem you’re having?
– Icaro
No problem, I don’t know how to count the likes, the codex is all right, but there’s no line on how to count the likes...
– Wallace Roberto
You will need to use a Switch, as soon as you open Activity to find out if you’ve already liked it. If you do, click remove, if you don’t like it. In your print it looks like it’s working. If you’re in doubt about the amount of likes. You just need to take the "branch" likes and make a size();
– Icaro
Okay, the part of the button is already clickable.
– Wallace Roberto
Do you have any idea how I do it so that you tell . Hild from firebase?
– Wallace Roberto
You must have a class, which encapsulates the content of the blog post. Adds a variable, which counts the Likes. It can be a list or even an int. https://firebase.google.com/docs/database/android/start/
– Icaro