0

I want to create Single and Double click on Button in Android... Thanks for help in Advance.

I have already tried using button.setOnClickListener() for single click on button but i couldn't find double click on button

Sai's Stack
  • 1,345
  • 2
  • 16
  • 29
  • possible duplicate of [Implement double click for button in Android](http://stackoverflow.com/questions/4849115/implement-double-click-for-button-in-android) – Steve Benett Nov 02 '14 at 11:28
  • i have implemented using Handler and Thread but its not up to the marks...like prints Toast message for First Click..for Double click i have to click 2 times...This is my problem... – Sai's Stack Nov 02 '14 at 11:34
  • I have implemented same as what u have mentioned above... – Sai's Stack Nov 02 '14 at 11:34

1 Answers1

0

Try this code : (btn is the button you want to check for single and double click)

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();
        }


    }
});
Arjun Komath
  • 2,802
  • 4
  • 16
  • 24