title: RelativeLayout with buttons
body: <p>I want to add number of buttons to RelativeLayout dynamically, but my code doesn't work. It adds them to the same place on the display.  </p>
  
  <pre><code>private void createButtons() {
          buttons = new ArrayList&lt;Button&gt;();  
          RelativeLayout bg = (RelativeLayout) findViewById(R.id.Bg);
          RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                  RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
  
          for(int i = 0; i &lt; channels.size(); i++){ 
              Button newButton = new Button(this);
              newButton.setId(i);
              newButton.setText(channels.get(i).getTitle());
              buttons.add(newButton);
              if(i &gt; 0){
                  lp.addRule(RelativeLayout.RIGHT_OF, i-1);
                  bg.addView(newButton, lp);
              }else{
                  bg.addView(newButton);
              }
          }
  
      }
  </code></pre>
  
  <p>What should I fix to make it work?</p>