title: Differentiate Single click and double click of a imageView in android
body: <p>I have tried the following code to differentiate single click and double click. Single click is ok. When I double click the imageview, code inside both the single click and double click part execute.</p>
  
  <pre><code>private static final long DOUBLE_PRESS_INTERVAL = 250; // in millis
      private long lastPressTime;
      boolean mHasDoubleClicked;
  
  img_feat_orgn_item.setOnClickListener(new OnClickListener() {
   @Override
      public void onClick(View v) {
      // TODO Auto-generated method stub
      findDoubleClick();
      }
      });
  
  private boolean findDoubleClick() {
          // Get current time in nano seconds.
      long pressTime = System.currentTimeMillis();
          // If double click...
          if (pressTime - lastPressTime &lt;= DOUBLE_PRESS_INTERVAL) {
              mHasDoubleClicked = true;           
              startActivity(new Intent(
                      Wv_HomePage.this,
                      NewDonation.class));
              // double click event....
          } else { // If not double click....
              mHasDoubleClicked = false;
              Handler myHandler = new Handler() {
                  public void handleMessage(Message m) {
                      boolean mHasDoubleClicked = false;
                      if (!mHasDoubleClicked) {
                          // single click event
                          feature_class_val = listData_Feature_Organization
                                  .get(j);
                          Intent intent = new Intent(
                                  Wv_HomePage.this,
                                  OrganizationDetails.class);
                          Bundle b = new Bundle();
                          b.putString("orgn_name",
                                  feature_class_val.name);
                          intent.putExtras(b);
                          startActivity(intent);
  
                      }
                  }
              };
              Message m = new Message();
              myHandler.sendMessageDelayed(m, DOUBLE_PRESS_INTERVAL);
          }
          lastPressTime = pressTime;
          return mHasDoubleClicked;
      }
  </code></pre>