title: How to get OnClick() from programmatically added buttons?
body: <p>I have added some buttons with the following lines:</p>
  
  <pre><code>for (int i=0; i&lt;XML.size(); i++) {
  //add button
  ToggleButton b = new ToggleButton(this); 
  // Setting the parameters
  lefttextv.setLayoutParams(lleft); 
  b.setLayoutParams(bright);
  //customize button
      b.setOnClickListener(this);
  b.setId(id_button);
  System.out.println(id_button);
  b.setHeight(100);
  b.setWidth(200);
  // Adding to the RelativeLayout as a child
  layouth.addView(lefttextv);
  layouth.addView(b);
      id_button++;  
      }
  </code></pre>
  
  <p>But how can I get the OnClick() methods for those? I already implemented View.OnClickListener with this method:</p>
  
  <pre><code>@Override
  public void onClick(View v) {
      // TODO Auto-generated method stub
      switch (v.getId())
      {
      case id_button: Log.d("Button 0","Button 0 pressed);
          break;
      }
  }
  </code></pre>
  
  <p>But this does not work, how do I get the Id?</p>