Adding item to view programatically in android
<p>I am trying to find out how I can add an item (from xml drawable/workaround_item.xml) in a LinearLayout that is vertically aligned.</p>

<p>  </p>

<pre><code>    &lt;LinearLayout
        android:layout_width="100dp"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:layout_alignParentLeft="true"
        android:gravity="center_vertical"&gt;            
        &lt;ImageView 
            android:id="@+id/home_image"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true" /&gt;           
        &lt;TextView
            android:id="@+id/home_team" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true" 
            android:gravity="center_horizontal"
            android:textStyle="bold"
            android:textSize="12sp"
            android:textColor="#fff"/&gt;          
    &lt;/LinearLayout&gt;

    &lt;LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:gravity="center_vertical"
        android:layout_centerHorizontal="true"&gt;
        &lt;TextView 
            android:id="@+id/game_cship" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true" 
            android:gravity="center_horizontal|center_vertical"
            android:textStyle="bold"
            android:textSize="10sp"/&gt;               
        &lt;TextView 
            android:id="@+id/game_score" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true" 
            android:gravity="center_horizontal"
            android:textStyle="bold"
            android:textColor="#fff" android:textSize="24sp"/&gt;          
        &lt;TextView 
            android:id="@+id/game_date" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true" 
            android:gravity="center_horizontal"
            android:textStyle="bold"
            android:textSize="10sp"/&gt;           
    &lt;/LinearLayout&gt;

    &lt;LinearLayout
        android:layout_width="100dp"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:gravity="center_vertical"
        android:layout_alignParentRight="true"&gt;                       
        &lt;ImageView 
            android:id="@+id/away_image"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true" /&gt;           
        &lt;TextView 
            android:id="@+id/away_team" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:gravity="center_horizontal"
            android:textStyle="bold"
            android:textSize="12sp"
            android:textColor="#fff" /&gt;     
    &lt;/LinearLayout&gt;
</code></pre>

<p></p>

<p>At the beggining I was trying to use a ListView but as far I as know there is a bug using listview inside a scrollview. I was doing this because i have more components on the view that should be scrolled together with the list view. So I decided to remove the listview and implement a simple linear layout where i will be adding each element bellow other and so on.</p>

<p>The layout for the activity is as folow (layout/workaround.xml) and i would like to start adding the elements below the top bar.</p>

<pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"    
android:id="@+id/linearid" &gt;

&lt;/LinearLayout&gt;
</code></pre>

<p>Thats my java code:</p>

<pre><code>public class DemoActivity3 extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.workaround);

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout ll = (LinearLayout) this.findViewById(R.id.linearid);

    for(int i = 1; i&lt; 15; i++) {        
        View item = inflater.inflate(R.layout.workaround_item, null);
        TextView x = (TextView) item.findViewById(R.id.game_score);
        x.setText("Score" + i);
        TextView ht = (TextView) item.findViewById(R.id.home_team);
        ht.setText("HomeTeam" + i);
        TextView at = (TextView) item.findViewById(R.id.away_team);
        at.setText("AwayTeam"+i);
        ImageView hi = (ImageView) item.findViewById(R.id.home_image);
        hi.setImageResource(R.drawable.gremio);
        ImageView ai = (ImageView) item.findViewById(R.id.away_image);
        ai.setImageResource(R.drawable.goias);
        ll.addView(item,ViewGroup.LayoutParams.WRAP_CONTENT);
    }       

}
</code></pre>

<p>Thats the result i am getting: <a href="http://twitpic.com/3562yu" rel="nofollow">http://twitpic.com/3562yu</a></p>

<p>Does android allow us to do this? If so, Hoe can I add the elements and set their values? (this layout will be dispalying results of soccer games).</p>

<p>Many Thanks
T</p>
