title: onLongClick listener for group of buttons in Android
body: <p>In my Android application, I want to create a fragment that works like a keypad. I have <strong>one function</strong> which handle <strong>onClick</strong> for all 9 keys. I want to know is there anyway to write just one function to handle <strong>onLongClick</strong> for all these 9 keys too.</p>
  
  <p>here is layout xml :</p>
  
  <pre><code>   &lt;Button
      android:id="@id/testButton"
      android:layout_width="70dp"
      android:layout_height="55dp"
      android:layout_margin="2dp"
      android:background="@drawable/keypad_round_button"
      android:text="1"
      android:textColor="@color/black_1" 
      android:onClick="keypadSetNote"
      android:longClickable="true"/&gt;
  &lt;Button
      android:id="@id/testButton"
      android:layout_width="70dp"
      android:layout_height="55dp"
      android:layout_margin="2dp"
      android:background="@drawable/keypad_round_button"
      android:text="2"
      android:longClickable="true"
      android:textColor="@color/black_1"
      android:onClick="keypadSetNote"
       /&gt;
  </code></pre>
  
  <p>Here is OnlongClick listener :</p>
  
  <pre><code>        Button button = (Button) findViewById(R.id.testButton);
      button.setOnLongClickListener(new View.OnLongClickListener() {
          public boolean onLongClick(View v) {
              Button clickedButton = (Button) v;
              String buttonText = clickedButton.getText().toString();
              Log.v(TAG, "button long pressed --&gt; " + buttonText);
              return true;
          }
      });
  </code></pre>
  
  <p>I gave all keys same ID to handle all <em>onLongClick</em> actions in one function, but it just work for the first key. Is there anyway to define something like group button in Android ??? Or I have to write OnLongClick listener for all of them separately ???</p>