title: Android: How to catch click on any button in Linear Layout?
body: <p>I have the following Layout:</p>
  
  <pre><code>&lt;LinearLayout
      android:id="@+id/group_button_layout"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:gravity="center"
      android:layout_centerHorizontal="true"&gt;
  
      &lt;Button
          android:id="@+id/group_button_1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textSize="12sp"
          android:text="Week"/&gt;
  
      &lt;Button
          android:id="@+id/group_button_2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textSize="12sp"
          android:padding="0dp"
          android:text="Month"/&gt;
  
      &lt;Button
          android:id="@+id/group_button_3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textSize="12sp"
          android:text="Quarter"/&gt;
  
      &lt;Button
          android:id="@+id/group_button_4"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textSize="12sp"
          android:text="Half Year"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>I created the onClickListener on layout like that:</strong></p>
  
  <pre><code> private void initViews() {
       mGroupedButtonLayout = (LinearLayout) findViewById(R.id.group_button_layout);
   }
  
   private void initListeners() {
       mGroupedButtonLayout.setOnClickListener(mButtonGroupListener);
   }
  </code></pre>
  
  <p><strong>And I thought that after click on a button onClick event will be triggered:</strong></p>
  
  <pre><code>private View.OnClickListener mButtonGroupListener = new View.OnClickListener() {
      public void onClick(View v) {
          Logger.d("Clicked");
          Logger.d(String.valueOf(v.getId()));
          // do something when the button is clicked
      }
  };
  </code></pre>
  
  <p>Is it possible to catch onClick event on every button without the need to create a listener for each button?</p>