java - Like counter Firebase Android -
i made app button, add counter...but i'm confused. can me? how can add counter? have 2 functions:
first
viewholder.mlikebtn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { mprocesslike = true; if(mprocesslike){ 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) { } }); } } }
second (it's change colour of button)
public void setlikebtn(final string post_key){ mdatabaselike.addvalueeventlistener(new valueeventlistener() { @override public void ondatachange(datasnapshot datasnapshot) { if(datasnapshot.child(post_key).haschild(mauth.getcurrentuser().getuid())){ mlikebtn.setimageresource(r.mipmap.likepieno); }else{ mlikebtn.setimageresource(r.mipmap.likevuoto); } } @override public void oncancelled(databaseerror databaseerror) { } }); }
Comments
Post a Comment