private static final int max_interval_for_click = 250; private static final int max_distance_for_click = 100; private static final int max_double_click_interval = 500; int mdownx = 0; int Mdow NY = 0; int mtempx = 0; int mtempy = 0; Boolean miswaitupevent = false;   ; Boolean Miswaitdoubleclick = false; Runnable mtimerforupevent = new Runnable () { p ublic void Run () { if (miswaitupevent) { LOG.D (log_tag, "The MTim Erforupevent have executed, so set the Miswaitupevent as false "); MI Swaitupevent = false; } else { &N Bsp LOG.D (LOG_TAG,&NBSp "The mtimerforupevent has executed, miswaitup Event is false,so does nothing "); } } };&NB Sp @Override public boolean ontouchevent (Motionevent event) { if (!miswaitupev ENT && event.getaction ()! = Motionevent.action_down) { return Super.ontou Chevent (event); } switch (event.getaction ()) { & nbsp Case motionevent.action_down: MDOWNX = (int) event.getx (); &N Bsp MDOWNY = (int) event.gety (); miswaitupevent = true; &N Bsp postdelayed (mtimerforupevent, Max_interval_for_click); Break; case motionevent.action_move: MTEMPX = (int) event.g EtX (); mtempy = (int) event.gety (); if ( Math.Abs (MTEMPX-MDOWNX) > max_distance_for_click || Math.Abs (Mtempy-mdowny) > Max_distance_for_click) { Miswaitupe Vent = false; removecallbacks (mtimerforupevent); &NBSP ; LOG.D (Log_tag, "The move distance too far:cancel the click"); &NBSP ; } break; Case Motionevent.action_up:&nbs P MTEMPX = (int) event.getx (); mtempy = (int) EV Ent.gety (); &nBsp if (Math.Abs (MTEMPX-MDOWNX) > max_distance_for_click &N Bsp | | Math.Abs (Mtempy-mdowny) > Max_distance_for_click) { Miswaitupe Vent = false; removecallbacks (mtimerforupevent); &NBSP ; LOG.D (log_tag, &NB Sp "The touch down and up distance too far:cancel the click"); break; } else { Miswaitupe Vent = false; removecallbacks (mtimerforupevent); &NBSP ; Onsingleclick (); &NBSP return Super.ontouchevent (event); } case motionevent.action_cancel: miswaitupevent = false; &N Bsp Removecallbacks (mtimerforupevent); LOG.D (Log_tag, "the Touch Cancel state : Cancel the Click "); break; default: &NBS P LOG.D (Log_tag, "irrelevant motionevent State:" + event.getaction ()); }&NBS P return super.ontouchevent (event); } Runnable Mtimerforsecondclick = new Run Nable () { @Override public void run () { & nbsp if (Miswaitdoubleclick) { LOG.D (log_tag, &nbsP "The Mtimerforsecondclick has Executed,so as a Singleclick");   ; Miswaitdoubleclick = false; &NBS P /At this can do something for singleclick!! } else { LOG.D (LOG_TAG,&N Bsp "The Mtimerforsecondclick has executed, the D Oubleclick have executed, so do thing "); } } &nbs P }; public void Onsingleclick () { if (Miswaitdoubleclick) { &NB Sp OnDoubleClick (); Miswaitdoubleclick = false; &N Bsp Removecallbacks (Mtimerforsecondclick); &NBSp Else { Miswaitdoubleclick = true; &NBS P Postdelayed (Mtimerforsecondclick, Max_double_click_interval); } } public void OnDoubleClick () { LOG.D (Log_tag, "We can do sth for double click here");   ; }