title: Adding TextView into another layout programatically
body: <p>I am strugling with one problem. I have got one main view with two layouts inside it:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".TestMainActivity" &gt;
  
      &lt;HorizontalScrollView
          android:id="@+id/menuView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true" &gt;
  
          &lt;LinearLayout
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:orientation="horizontal" &gt;
  
              &lt;Button
                  android:id="@+id/button1"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="Add" /&gt;
  
              &lt;Button
                  android:id="@+id/button2"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="Add2" /&gt;
          &lt;/LinearLayout&gt;
      &lt;/HorizontalScrollView&gt;
  
      &lt;com.test.board.Board
          android:id="@+id/boardView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/menuView"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="30dp" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Board layout is my class which is inhariting from ViewGroup. What I want to achive is to add TextView (or any other Layout elent like Image, button, another layout) into my canvas (borad).</p>
  
  <p>This is how am I doing it now:</p>
  
  <pre><code>Button textBold = (Button) findViewById(R.id.button1);
          textBold.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
                  TextView txt1 = new TextView(TestMainActivity.this);
                  txt1.setText("Sample text");
                  txt1.setTextColor(Color.BLUE);
                  txt1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
                  myView.addView(txt1);
              }
          });
  </code></pre>
  
  <p>myView is object of class Board.</p>
  
  <p>When I am checking the number of child elements is increasing each time, but I don't see this TextView.</p>
  
  <p>Can someone please tell me, what I have to do to make this text visible?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>It might be a mistake that I didn't put whole onCreat method, where I initialize myView. So there it is:</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          myView = (Board) findViewById(R.id.boardView1);
          myView.setBackgroundColor(Color.WHITE);
          myView.refreshView(); //function below
  
          Button textBold = (Button) findViewById(R.id.button1);
          textBold.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
                  TextView txt1 = new TextView(TestMainActivity.this);
                  txt1.setText("Sample text");
                  txt1.setTextColor(Color.BLUE);
                  txt1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
                  myView.addView(txt1);
              }
          });
  </code></pre>
  
  <p>there is refreshView() function just for extra:</p>
  
  <pre><code>public void refreshView() {
          // redraw the view
          invalidate();
          requestLayout();
      }
  </code></pre>