title: OnClick event handler on buttons created programmatically
body: <p>I'm developing an Android 3.1 application that uses fragments.</p>
  
  <p>On one of those fragments a need to create <strong>n</strong> buttons and set an onClick event handler for each of them.</p>
  
  <p>To do it I want to create a method on <code>FragmentActivity</code> that handles those events but I don't know how. Note: <code>FragmentActivity</code> is a <code>android.support.v4.app.FragmentActivity</code> that manages all fragments using <code>android.support.v4.view.ViewPager</code>.</p>
  
  <p>On another fragment I have the following <code>XML</code>code:</p>
  
  <pre><code>    &lt;Button
          android:id="@+id/btnTakeArticlePhotos"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="right"
          android:text="@string/btn_take_photo"
          android:onClick="onTakePhotoClick" /&gt;
  </code></pre>
  
  <p>And this code on <code>FragmentActivity</code>:</p>
  
  <pre><code>public void onTakePhotoClick(View view)
  {
      Log.v("FillEReportFragmentActivity", "onTakeFactoryPhotoClick");
      int imgType, imgSubType;
  
      switch (view.getId())
      {
          case R.id.btnTakeFactoryPhotos:
              imgType = ImageType.EREPORT;
              imgSubType = SubImageType.EREPORT_FACTORY_OUTLOOK;
          break;
          case R.id.btnTakeArticlePhotos:
              imgType = ImageType.ARTICLE;
              imgSubType = SubImageType.NONSET;
          default:
              imgType = -1;
              imgSubType = -1;
          break;
      }
  
      Intent intent = new Intent(FillEReportFragmentActivity.this, CameraActivity.class);
      intent.putExtra(BundleKeys.tablePk, eReportId);
      intent.putExtra(BundleKeys.imgType, imgType);
      intent.putExtra(BundleKeys.imgSubType, imgSubType);
  
      startActivityForResult(intent, CAMERA_REQUEST_CODE);
  }
  </code></pre>
  
  <p><strong>I want to do the same with these <code>n</code> buttons: create a method on <code>FragmentActivity</code> to handle all onClick events.</strong></p>
  
  <p>I see that if I want to handle onClick event on a button created programmatically I need to implement <code>onClickEventListener</code>.</p>
  
  <p>How can I handle those onClick events on <code>FragmentActivity</code>? or is there a better approach?</p>