Posts

Showing posts with the label firebase-database

How to add like counter Android Studio Firebase

How to add like counter Android Studio Firebase this is the database link 1can anybody help me to add a like counter to this.please please it should display the no:of likes and decease it when like is taken back my java code is below private void onLikeClicked(View v) { boolean isLiked = !btnLike.isSelected(); final String currentUserKey = User.currentKey(); DatabaseReference likes = FirebaseDatabase.getInstance().getReference().child(Const.kDataLikeKey); DatabaseReference curLike = likes.child(mPostRef.getKey()).child(currentUserKey).child("liked"); // update Model curLike.setValue(isLiked); // update UI btnLike.setSelected(isLiked); } This increment like count but doesn't decrements it i want it to get decremented when clicked back 1 Answer 1 Your question is not entirely clear but if you are trying to make a functionality like social media post wher...

Undefined UserId

Image
Undefined UserId So I am trying to do a 1v1 chat but the userid is showing up as undefined when I push up the message, and the other-other users id doesn't show. if (user.emailVerified) { userPic = user.photoURL; userId = user.id; displayName = user.displayName; var pm = database.ref('chat/' + userId); // Create a new message and add it to the list. pm.push({ displayName: displayName, userId: userId, pic: userPic, text: myString.toString(), timestamp: new Date().getTime(), // unix timestamp in milliseconds }) } This is is the code I am using to push the message up Edit This is the userID I am talking about you say Undefined UserId ... but there's only user.id or the global userId - so where is this UserId that is undefined - certainly not in your code - except of course it would be, but then so is ljhgwvliueghgl as that too isn't ever assigned a value ...