Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want to reduce the coding lines then use <code>View's OnClick() with switch statement</code> and if you want to handle separately all click (for easily understanding and maintaining code) then use separate all <code>button's onClick().</code></p> <p><strong>Update:</strong></p> <p>If you have declared Buttons in your Activity layout xml file, than write attribute <code>android:onClick=""</code> with same method name for all buttons and implement that method in your activity. Now you have one method for all buttons and in that method differentiate buttons with id.</p> <p><strong>Example:</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;Button android:id="@+id/button1" android:layout_width="wrap_content" android:onClick="buttonOnClick" android:layout_height="wrap_content" android:text="Hello, I am a Button 1" /&gt; &lt;Button android:id="@+id/button2" android:layout_width="wrap_content" android:onClick="buttonOnClick" android:layout_height="wrap_content" android:text="Hello, I am a Button 2" /&gt; &lt;Button android:id="@+id/button3" android:layout_width="wrap_content" android:onClick="buttonOnClick" android:layout_height="wrap_content" android:text="Hello, I am a Button 3" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Now in your Activity implement <code>buttonOnClick</code> like,</p> <pre><code>public void buttonOnClick(View view) { switch(view.getId()) { case R.id.button1: // Code for button 1 click break; case R.id.button2: // Code for button 2 click break; case R.id.button3: // Code for button 3 click break; } } </code></pre> <p>Or you can apply same switch case for dynamically added buttons in your activity, like instead of <code>buttonOnClick</code> you have to use <strong>implemented View's OnClickListerner's</strong> <code>onClick</code>.</p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. 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