I am trying to use this code to prevent multiple clicks in ImageView, but this does not help.
Boolean isClicked = false;
@Override
public void onClick(View v)
{
if (v == imgClick && !isClicked)
{
isClicked = true;
Log.d(TAG, "button click");
try
{
Thread.sleep(2000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
isClicked = false;
}
}
In log cat, I can see 5 lines of “click on a button” when I click on ImageView 5 times as fast as possible. I see the log cat print the first line, wait a while (2 seconds), and then print the next line.
I think that when I click ImageView, the fired event moves to the queue in order, right? So how can I stop this?
I am also trying to use setEnable () or setClickable () instead of the isClicked variable, but it does not work either.
source
share