title: How to add custom view inside another custom view?
body: <p>I'm trying to add CustomViewBeta (an extended RelativeLayout) to CustomViewAlpha (an extended LinearLayout) -- the idea being that the CustomViewAlpha will hold a bunch of CustomViewBetas a la a ListView. No matter what I try, it doesn't work. I either see nothing -- no CustomViewBetas, or it gives me an NPE when I try setText on one of the TextViews inside the CustomViewBeta</p>
  
  <p>CustomViewAlpha works fine since it's hard-coded in the Fragment's XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout
     ...&gt;
      &lt;com.path.CustomViewAlpha
          android:id="@+id/customviewalpha"
          android:orientation="vertical"
          android:layout_gravity="center_vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent"/&gt;
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>With the code being:</p>
  
  <pre><code>public class CustomViewAlpha extends LinearLayout {
  private Context mContext;
  
  public CustomViewAlpha (Context context) {
      super(context);
      this.mContext = context;
  }
  
  public CustomViewAlpha (Context context, AttributeSet attrs) {
      super(context, attrs);
      this.mContext = context;
  }
  
  public CustomViewAlpha (Context context, AttributeSet attrs, int defStyle){
      super(context, attrs,defStyle);
      this.mContext = context;
  }
  
  public void addCustomViewBeta(String someString){
      CustomViewBeta customViewBeta = new CustomViewBeta(mContext);
      addView(customViewBeta);
  }
  </code></pre>
  
  <p>CustomViewBeta is not hard-coded in the Fragment's XML and get's added programmatically:</p>
  
  <p>public class CustomViewBeta extends RelativeLayout{
      private Context mContext;</p>
  
  <pre><code>private TextView textView;
  
  public CustomViewBeta (Context context) {
      super(context);
      this.mContext = context;
      init();
  }
  
  public CustomViewBeta (Context context, AttributeSet attrs) {
      super(context, attrs);
      this.mContext = context;
      init();
  }
  
  public CustomViewBeta (Context context, AttributeSet attrs, int defStyle){
      super(context, attrs,defStyle);
      this.mContext = context;
      init();
  }
  
  
  private void init() {
      LayoutInflater.from(mContext).inflate(R.layout.customviewbeta, null, false);
      textView = (TextView) findViewById(R.id.tripleexpandablelistview_category_name);
      textView.setText("ASDASDASDAD");
  }
  </code></pre>
  
  <p>With this XML being:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;com.path.CustomViewBeta
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"&gt;
  
      &lt;TextView
          android:id="@+id/customviewbeta_textview"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/&gt;
  
  &lt;/com.path.CustomViewBeta&gt;
  </code></pre>
  
  <p>I usually get hit with a NPE on the "textView.setText("ASDASDASDAD");" line because the TextView is null. Is there something I'm missing? Should I not try to inflate an XML for the CustomViewBeta and just do it programmatically (adding the textviews one by one programmatically?)? Thanks.</p>