Skip to content

Commit fd6ad40

Browse files
Merge pull request #5 from AlexJuca/master
Could create too many handler references everytime the user clicks.
2 parents 3fbbcff + dbf07af commit fd6ad40

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

app/src/main/java/com/pedromassango/doubleclick/DoubleClick.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class DoubleClick implements View.OnClickListener {
1212
private int clicks;
1313
private boolean isBussy = false;
1414
private final DoubleClickListener doubleClickListener;
15-
15+
Handler mHandler = new Handler();
1616
public DoubleClick( DoubleClickListener doubleClickListener) {
1717
this.doubleClickListener = doubleClickListener;
1818
}
@@ -26,10 +26,8 @@ public void onClick( final View v) {
2626

2727
// Increase clicks count
2828
this.clicks++;
29-
Handler handler = new Handler();
30-
long TIME_TO_LISTEN_A_DOUBLE_CLICK = 250L; // Time to wait the second click.
31-
32-
handler.postDelayed(new Runnable() {
29+
long DOUBLE_CLICK_INTERVAL = 250L; // Time to wait the second click.
30+
mHandler.postDelayed(new Runnable() {
3331
public final void run() {
3432

3533
if (clicks >= 2) { // Double tap.
@@ -44,7 +42,7 @@ public final void run() {
4442
clicks = 0;
4543
isBussy = false;
4644
}
47-
}, TIME_TO_LISTEN_A_DOUBLE_CLICK);
45+
}, DOUBLE_CLICK_INTERVAL);
4846
}
4947
}
5048
}

0 commit comments

Comments
 (0)