title: Dynamically creating Buttons and setting onClickListener
body: <p>I have problem with handling dynamically created Buttons on Android. I'm creating N buttons and I have to do the same method when button is clicked but I have to know which button is clicked.</p>
  
  <pre><code>for (int i = 0; i &lt; NO_BUTTONS; i++){
          Button btn = new Button(this);
          btn.setId(2000+i);
  
          ...
  
          btn.setOnClickListener((OnClickListener) this);
          buttonList.addView(btn);
          list.add(btn);
  </code></pre>
  
  <p>Cucurrently I'm adding ID to every button and I'm using the method below to see which button was clicked. (line <code>btn.setId(2000+i);</code> and <code>btn.setOnClickListener((OnClickListener) this);</code>). This method is also implemented in the activity. </p>
  
  <pre><code>@Override
  public void onClick(View v) {
      switch (v.getId()){
          case 2000: selectButton(0);
          break;
  
          ...
  
          case 2007: selectButton(7);
          break;
      }
   }
  </code></pre>
  
  <p>This doesn't look good to me so i'm asking is there some better way to do this? or how to send some information to onclick event? any suggestions?</p>