title: AddView To Fragment not showing in Android
body: <p>I have a fragment in which I'm trying to add a class "CategoryOption" which extends <code>LinearLayout</code>. But, when I do AddView in my <code>onCreateView()</code>, it shows nothing.</p>
  
  <p>Here is my Code for the Fragment:</p>
  
  <pre><code>public class ContentFragment extends Fragment {
  
  LinearLayout navBarLayout;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      View view = inflater.inflate(R.layout.content_fragment, container, false);
  
      navBarLayout = (LinearLayout) view.findViewById(R.id.navbar_layout);
      navBarLayout.addView(new CategoryOption(getActivity(), R.drawable.ic_action_rss, "RSS Feed"));
  
      return view;    
  }
  }
  </code></pre>
  
  <p>Here is my content_fragment xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" &gt;
  
  &lt;HorizontalScrollView
      android:id="@+id/horizontalScrollView1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content" &gt;
  
      &lt;LinearLayout
          android:id="@+id/navbar_layout"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:background="@android:color/darker_gray"
          android:orientation="horizontal" &gt;
  
      &lt;/LinearLayout&gt;
  &lt;/HorizontalScrollView&gt;
  
  &lt;LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical" &gt;
  
      &lt;TextView
          android:id="@+id/textView2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Large Text"
          android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  
      &lt;Button
          android:id="@+id/button1"
          style="?android:attr/buttonStyleSmall"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Button" /&gt;
  
      &lt;RadioButton
          android:id="@+id/radioButton1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="RadioButton" /&gt;
  
      &lt;Button
          android:id="@+id/button2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Button" /&gt;
  
      &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="TextView" /&gt;
  
  &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Here is My CategoryOption Class:</p>
  
  <pre><code>public class CategoryOption extends LinearLayout {
  
  int iconId;
  String optionName;
  LinearLayout optionLayout;
  TextView tvOption;
  ImageView ivIcon;
  
  public CategoryOption(Context context) {
      super(context);
      // TODO Auto-generated constructor stub
  }
  
  public CategoryOption(Context context, int iconId, String optionName) {
      super(context);
  
      this.iconId = iconId;
      this.optionName = optionName;
  
      optionLayout = new LinearLayout(context);
      tvOption = new TextView(context);
      ivIcon = new ImageView(context);
  
      setupLayout();
      setupTextView();
      setupImageView();
  
      optionLayout.addView(ivIcon);
      optionLayout.addView(tvOption);
  }
  
  private void setupImageView() {
      // TODO Auto-generated method stub
      LayoutParams params = new LayoutParams(36, 36);
      params.setMargins(0, 0, 0, 4);
      ivIcon.setLayoutParams(params);
      ivIcon.setImageResource(iconId);
  }
  
  private void setupLayout() {
      // TODO Auto-generated method stub
      optionLayout.setLayoutParams(new LayoutParams(
              LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
      optionLayout.setOrientation(LinearLayout.VERTICAL);
      optionLayout.setGravity(Gravity.CENTER);
      optionLayout.setPadding(4, 4, 4, 4);
      optionLayout.setBackgroundColor(Color.parseColor("#DEDEDE"));
  }
  
  private void setupTextView() {
      // TODO Auto-generated method stub
      tvOption.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
              LayoutParams.WRAP_CONTENT));
      tvOption.setTextColor(Color.parseColor("#111111"));
      tvOption.setText(optionName);
  }
  
  public int getIconId() {
      return iconId;
  }
  
  public String getOptionName() {
      return optionName;
  }
  </code></pre>
  
  <p>}</p>