Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using the <code>android:onClick="doSomething"</code> XML tag is very easy.</p> <p>In the Context where you have inflated the layout(usually an Activity) you must declare a function like that</p> <p><code>public void doSomething(View view)</code></p> <p>You can find this information in the Documentation here</p> <p><a href="http://developer.android.com/reference/android/view/View.html#attr_android:onClick" rel="nofollow">http://developer.android.com/reference/android/view/View.html#attr_android:onClick</a></p> <p>By this way you get a cleaner Activity if the Image onClick is not dynamic.</p> <p><strong>EDIT</strong></p> <p>Example, in the XML Layout</p> <pre><code>&lt;ImageView android:id="@+id/image_id" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/image" android:onClick="doSomething" /&gt; </code></pre> <p>In the Activity if you want to open a new Activity for example</p> <pre><code>class ImageActivity extend Activity{ @Override public void onCreate(Bundle params){ //... } public void doSomething(View view){ startActivity(new Intent(this, AnotherActivity.class)); } } </code></pre> <p>In the View element you get the clicked view, so you can identify which element has triggered the function.</p> <pre><code>public void doSomething(View view){ if( view.getId() == R.id.image_id) startActivity(new Intent(this, AnotherActivity.class)); else Log.i("Image", "Try to open the Activity from another view different from ImageView") } </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.
    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