Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Any view can be setup with an <code>onClickListener()</code> which is part of the view class. The easiest way to do it is when you setup the references to your view in the <code>onCreate()</code> method. Here is an example for a image view:</p> <pre><code>ImageView iv = (ImageView) findViewByID(R.id.example); iv.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Do what you need to do on click .... } }); </code></pre> <hr> <p>UPDATE: DOUBLE TAP</p> <p>Here is a sample activity which implements basic double tap detection on an image view:</p> <pre><code>import android.app.Activity; import android.os.Bundle; import android.os.SystemClock; import android.view.MotionEvent; import android.view.View; import android.widget.ImageView; import android.widget.Toast; public class DoubleTapActivity extends Activity { //Set the double tap delay in milliseconds protected static final long DOUBLE_CLICK_MAX_DELAY = 1000L; private ImageView iView; private long thisTime = 0; private long prevTime = 0; private boolean firstTap = true; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); iView = (ImageView)findViewById(R.id.iView); iView.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub if(firstTap){ thisTime = SystemClock.uptimeMillis(); firstTap = false; } else { prevTime = thisTime; thisTime = SystemClock.uptimeMillis(); //Check that thisTime is greater than prevTime //just incase system clock reset to zero if(thisTime &gt; prevTime){ //Check if times are within our max delay if((thisTime - prevTime) &lt;= DOUBLE_CLICK_MAX_DELAY){ //We have detected a double tap! Toast.makeText(DoubleTapActivity.this, "DOUBLE TAP DETECTED!!!", Toast.LENGTH_LONG).show(); //PUT YOUR LOGIC HERE!!!! } else { //Otherwise Reset firstTap firstTap = true; } } else { firstTap = true; } } return false; } }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload