title: Android: Add button in a View
body: <p>Am doing a Titanium Module (Just Android code), and I need to present a button in a View, so there is no Activity and no xml layout.
  I have the following code to add the button in my view:</p>
  
  <pre><code>public class MyView extends ViewGroup {
   public MyView(Context context) {
    super(context);
    ...
    Button b=new Button(context);
    b.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 
                  LayoutParams.WRAP_CONTENT)); 
    b.setText("Some Text");
    this.addView(b);
   }
  }
  </code></pre>
  
  <p>Searching in StackOverflow, this code should work... But the button is never shown.
  How can I add a button to a View or ViewGroup?</p>
  
  <p>EDIT add onLayout() method:</p>
  
  <pre><code>@Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
       LinearLayout l1=new LinearLayout(_context);
       l1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
       l1.setOrientation(LinearLayout.VERTICAL);
       Button b1=new Button(_context);
       b1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
       b1.setText("Button");
       l1.addView(b1);
  
       this.addView(l1);
  }
  </code></pre>
  
  <p>Thanks for your help.-</p>