title: Inflating a LinearLayout dynamically - Android
body: <p>I'm trying to inflate a list of views in a <code>LinarLayout</code> directly in the <code>onCreate()</code> method from the activity. However, I'm having a problem somewhere in the code but I really can't see it, I'm turning around this problem for two days, I'm going crazy !</p>
  
  <p><strong>The problem is that when I run the activity, the linear layout is completely empty, there is only the title.</strong></p>
  
  <p><img src="https://i.stack.imgur.com/YxgyW.png" alt="enter image description here"></p>
  
  <p>Here is the important part of the code, <code>KeyItems</code> activity :</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.keyitems_layout);
      initializer();
      ll = (LinearLayout) findViewById(R.id.ll);
      LayoutInflater inflater = LayoutInflater.from(this);
      for (int i = 0; i &lt; list.size(); i++) {
          View view  = inflater.inflate(R.layout.keyitem_temp, ll, false); 
          final TextView ind = (TextView) view.findViewById(R.id.ind);
          final TextView item = (TextView) view.findViewById(R.id.item);
          ind.setText(list.get(i).get("id"));
          item.setText(list.get(i).get("item"));
          ll.addView(view);
      }
  }
  </code></pre>
  
  <p>Here is the <code>keyitems_layout</code> :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:background="@color/black" &gt;
  
      &lt;LinearLayout android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
          android:background="@color/black"&gt;
  
          &lt;TextView android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:padding="8dp" /&gt;
  
          &lt;TextView android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:gravity="center_horizontal"
              android:text="@string/key_items"
              android:textSize="36sp"
              android:textColor="@color/white" /&gt;
  
          &lt;TextView android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:padding="4dp" /&gt;
  
          &lt;LinearLayout android:id="@+id/ll"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_marginLeft="32dp"
              android:layout_marginRight="32dp"
              android:orientation="vertical"
              android:background="@color/white" &gt;
  
          &lt;/LinearLayout&gt;
  
          &lt;TextView android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:textColor="@color/white"
              android:text="caca"
              android:padding="32dp" /&gt;
  
          &lt;/LinearLayout&gt;
  
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>And finally, my <code>keyitem_temp.xml</code> which I'm inflating :</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="wrap_content"
      android:background="@color/black"
      android:padding="4dp"
      android:orientation="horizontal" &gt;
  
      &lt;TextView android:id="@+id/ind"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_gravity="center"
          android:gravity="center"
          android:textSize="18sp"
          android:textColor="@color/blue" /&gt;
  
      &lt;TextView android:id="@+id/item"
          android:layout_width="0dp"
          android:layout_weight="1"
          android:layout_height="match_parent"
          android:layout_gravity="center"
          android:gravity="center"
          android:textSize="18sp"
          android:textColor="@color/white"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I have an other activity called ItemsActivity which is the same code with some little differences and it works. Any suggestion? Thanks in advance.</p>