How To Stop Click Count In Java Android?
I have a problem related click count. The problem is, I can't stop click when a number a click is given. For example, I allow users to click a button 3 times, if clicks reached 3 t
Solution 1:
I think the trigger to do something might be when the click count is zero, not three:
if (clickcount == 0) {
mTitle.setVisibility(View.GONE);
rl2.setVisibility(View.GONE);
}
It isn't clear whether the above if
statement belongs nested inside the outer if
, or if it should be at the method level of onClick()
.
Note: We could have written if (clickCount <= 0)
, but there may not be a need to do this (nor may it be desirable), since after you have changed the visibility of those elements to GONE
once, you don't need to do it again.
Solution 2:
Make this Change,
privateintclickcount=3;
@OverridepublicvoidonClick(View v) {
// Do button click handling hereif ( posisi2==getAdapterPosition() ) {
clickcount--;
tombolbaca.setText("Baca " + clickcount + "x");
// try to stop count but it can'tif (clickcount <=0) <== make this change
{
mTitle.setVisibility(View.GONE);
rl2.setVisibility(View.GONE);
}
} // adapter
}
Solution 3:
try this
privateintclickcount=3;
@OverridepublicvoidonClick(View v) {
// Do button click handling hereif ( posisi2==getAdapterPosition() ) {
clickcount--;
tombolbaca.setText("Baca " + clickcount + "x");
// try to stop count but it can't, computer still countingif (clickcount == 0)
{
mTitle.setVisibility(View.GONE);
rl2.setVisibility(View.GONE);
}
} // adapter
} // onClick
Solution 4:
privateintclickcount=0;
@OverridepublicvoidonClick(View v) {
// Do button click handling hereif ( clickcount<3 ) {
clickcount++;
tombolbaca.setText("Baca " + clickcount + "x");
}
//Count stops here..else
{
mTitle.setVisibility(View.GONE);
rl2.setVisibility(View.GONE);
}
}
}
Post a Comment for "How To Stop Click Count In Java Android?"