title: Creating Imagebutton programmatically
body: <p>I want to create several ImageButtons programmatically. I am able to create them but the click event listener keeps receiving the same view (Button 2), whether I click on button 0 ,button1 or button 2.</p>
  
  <pre><code>    RelativeLayout gameBoard = (RelativeLayout) findViewById(R.id.RelGameboard);
  
      RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
      lp.addRule(RelativeLayout.CENTER_IN_PARENT,1);
  
      for(int i = 0 ; i &lt;  3 ; i++)
      {
  
          ImageButton btnGreen = new ImageButton(this);
          btnGreen.setImageResource(R.drawable.bola_verde);
          btnGreen.setLayoutParams(lp);
          btnGreen.setOnClickListener(mGreenBallOnClickListener);
          btnGreen.setBackgroundColor(Color.TRANSPARENT); 
          btnGreen.setTag(i);
          btnGreen.setId(i);
  
                      gameBoard.addView(btnGreen);
  
  
       }'
  </code></pre>
  
  <p>Click event listener:</p>
  
  <pre><code>private View.OnClickListener mGreenBallOnClickListener = new View.OnClickListener() {
  
      @Override
      public void onClick(View v) {
  
          //check which green ball was clicked
          ImageButton imgBtn = (ImageButton) v;
  
      Log.i("greeny","Clicked on green ball-&gt;"+imgBtn.getTag()+" v.ID-&gt;"+v.getId());
      }
  };
  </code></pre>
  
  <p>For any imagebutton drawn, when I click I get :  Clicked on green ball->2 v.ID->2</p>
  
  <p>The buttons are in different positions ( i set a different padding for each one of them but in order to simplify the code I didn't put it here )</p>