Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try using the onTouch event, or change the image for a imagebutton... </p> <p>But it's better if you do it with the main onClick method()</p> <pre><code>@Override public void onClick(final View v) { switch(v.getId()){ case R.id.myimage: //Do it when myimage is clicked Toast.makeText(class.this, "CLICKED!",Toast.LENGTH_SHORT).show(); break; case R.id.otherID: //Do something when other item is clicked break; } } </code></pre> <p>And say goodbye to the onClick listeners...</p> <p>Other options is setting the property onclick in the layout... An example:</p> <pre><code> &lt;ImageView android:id="@+id/myimage" android:layout_width="170dp" android:layout_height="115dp" android:onClick="yourmethodname" android:scaleType="centerCrop" android:src="@drawable/iconcamera3" /&gt; </code></pre> <p>And in the java class add:</p> <pre><code>public void yourmethodname(final View v) { Toast.makeText(class.this, "CLICKED!",Toast.LENGTH_SHORT).show(); //Do anything what you want to do on the onClick event } </code></pre> <p>I don't like to use the onclick listeners, so I use the methods and never has failed.. try it...</p> <p>EDIT: For use the first way, overriding the onClick method, first we have to implement onClickListener:</p> <pre><code>import android.view.View.OnClickListener; public class AnyClass extends Activity implements OnClickListener{ @Override public void onClick(final View v) { switch(v.getId()){ case R.id.myimage: //Do it when myimage is clicked Toast.makeText(class.this, "CLICKED!",Toast.LENGTH_SHORT).show(); break; case R.id.otherID: //Do something when other item is clicked break; } } } </code></pre>
 

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