Implement double click for button in Android

Anju picture Anju · Jan 31, 2011 · Viewed 45.4k times · Source

How can I implement double click for a button in Android? Should I use OnDoubleTapListener?

Answer

Parag Chauhan picture Parag Chauhan · Jan 31, 2011
int i = 0;
btn.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        i++;
        Handler handler = new Handler();
        Runnable r = new Runnable() {

            @Override
            public void run() {
                i = 0;
            }
        };

        if (i == 1) {
            //Single click
            handler.postDelayed(r, 250);
        } else if (i == 2) {
            //Double click
            i = 0;
            ShowDailog();
        }


    }
});