how to implement double click in android

Posted by Sanal Varghese on Stack Overflow See other posts from Stack Overflow or by Sanal Varghese
Published on 2012-04-02T05:19:14Z Indexed on 2012/04/02 5:29 UTC
Read the original article Hit count: 232

Filed under:

I am doing a project in which i want to display a particular message on single touch and another message on double touch using android.How can i implement it.

My sample code is below

if(firstTap){
            thisTime = SystemClock.u`enter code here`ptimeMillis();
            firstTap = false;
        }else{
            prevTime = thisTime;
            thisTime = SystemClock.uptimeMillis();

            //Check that thisTime is greater than prevTime
            //just incase system clock reset to zero
            if(thisTime > prevTime){

                //Check if times are within our max delay
                if((thisTime - prevTime) <= DOUBLE_CLICK_MAX_DELAY){

                    //We have detected a double tap!
                    Toast.makeText(AddLocation.this, "DOUBLE TAP DETECTED!!!", Toast.LENGTH_LONG).show();
                    //PUT YOUR LOGIC HERE!!!!

                }else{
                    //Otherwise Reset firstTap
                    firstTap = true;
                }
            }else{
                firstTap = true;
            }
        }
        return false;

© Stack Overflow or respective owner

Related posts about android