title: Dynamically add ListView in the code to ScrollView
body: <p>I am trying to add a <code>ListView</code> to a <code>ScrollView</code> inside the code. But it's not working for some reason. I am new to this. Can somebody help me out?</p>
  
  <pre><code>package net.pocketmagic.android.HeaderContentFooterGUI;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  
  import android.app.Activity;
  import android.graphics.Color;
  import android.graphics.Typeface;
  import android.os.Bundle;
  import android.view.Gravity;
  import android.view.Menu;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.view.ViewGroup.LayoutParams;
  import android.view.Window;
  import android.widget.Button;
  import android.widget.LinearLayout;
  import android.widget.ListView;
  import android.widget.RelativeLayout;
  import android.widget.ScrollView;
  import android.widget.SimpleAdapter;
  import android.widget.TextView;
  
  /* HeaderContentFooterGUI
   * 
   * Create a sample GUI with a header bar, scroll-able content and a footer
   * 
   * (C) 2011 Radu Motisan, radu.motisan@gmail.com
   * www.pocketmagic.net
   * All rights reserved.
   */
  
  public class HeaderContentFooterGUI extends Activity {
  
      final static int        idTopLayout = Menu.FIRST + 100,
                              idBack      = Menu.FIRST + 101,
                              idBotLayout = Menu.FIRST + 102;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          //Hide titlebar
          requestWindowFeature(Window.FEATURE_NO_TITLE);
  
          //Create our top content holder
          RelativeLayout global_panel = new RelativeLayout (this);
          global_panel.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
          global_panel.setGravity(Gravity.FILL);
  
          // +++++++++++++ TOP COMPONENT: the header
          RelativeLayout ibMenu = new RelativeLayout(this);
          ibMenu.setId(idTopLayout);
          ibMenu.setBackgroundDrawable(getResources().getDrawable(R.drawable.line));
          int ibMenuPadding = (int) 6;
          ibMenu.setPadding(ibMenuPadding,ibMenuPadding,ibMenuPadding,ibMenuPadding);
          RelativeLayout.LayoutParams topParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
          topParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
          global_panel.addView(ibMenu,topParams);
          // textview in ibMenu : card holder
          TextView cTV = new TextView(this);
          cTV.setText("Abirami Mega Mall");
          cTV.setTextColor(Color.rgb(255,255,255));
          int nTextH =  18;
          cTV.setTextSize(nTextH);
          cTV.setTypeface(Typeface.create("arial", Typeface.BOLD));
          RelativeLayout.LayoutParams lpcTV = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
          lpcTV.addRule(RelativeLayout.CENTER_IN_PARENT);
          ibMenu.addView(cTV, lpcTV);
  
          // +++++++++++++ BOTTOM COMPONENT: the footer
          nTextH =  13;
           ibMenuPadding = (int) 15;
          RelativeLayout ibMenuBot = new RelativeLayout(this);
          ibMenuBot.setId(idBotLayout);
          ibMenuBot.setBackgroundDrawable(getResources().getDrawable(R.drawable.line));
          ibMenuBot.setPadding(ibMenuPadding,ibMenuPadding,ibMenuPadding,ibMenuPadding);
          RelativeLayout.LayoutParams botParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
          botParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
          global_panel.addView(ibMenuBot,botParams);
          // textview in ibMenu : card holder
  
          TextView cTVBot = new TextView(this);
          cTVBot.setId(5001);
          cTVBot.setText("Home"); 
          cTVBot.setTextColor(Color.rgb(179,116,197));
          cTVBot.setTextSize(nTextH);
          cTVBot.setTypeface(Typeface.create("arial", Typeface.NORMAL));
          cTVBot.setPadding(ibMenuPadding,ibMenuPadding,ibMenuPadding,ibMenuPadding);
          RelativeLayout.LayoutParams lpcTVBot = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);   
          lpcTVBot.addRule(RelativeLayout.CENTER_VERTICAL);
          ibMenuBot.addView(cTVBot, lpcTVBot);
  
          TextView cTVBot2 = new TextView(this);
          cTVBot2.setId(5002);        
          cTVBot2.setText("Booking History");     
          cTVBot2.setTextColor(Color.rgb(179,116,197));
          cTVBot2.setTextSize(nTextH);
          cTVBot2.setTypeface(Typeface.create("arial", Typeface.NORMAL));
          cTVBot2.setPadding(ibMenuPadding,ibMenuPadding,ibMenuPadding,ibMenuPadding);
          RelativeLayout.LayoutParams lpcTVBot2 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);      
          lpcTVBot2.addRule(RelativeLayout.RIGHT_OF,cTVBot.getId() );
          lpcTVBot2.addRule(RelativeLayout.CENTER_VERTICAL);      
          ibMenuBot.addView(cTVBot2, lpcTVBot2);
  
          TextView cTVBot3 = new TextView(this);
          cTVBot3.setId(5003);        
          cTVBot3.setText("Help?");       
          cTVBot3.setTextColor(Color.rgb(179,116,197));
          cTVBot3.setTextSize(nTextH);
          cTVBot3.setTypeface(Typeface.create("arial", Typeface.NORMAL));
          cTVBot3.setPadding(ibMenuPadding,ibMenuPadding,ibMenuPadding,ibMenuPadding);
          RelativeLayout.LayoutParams lpcTVBot3 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);      
          lpcTVBot3.addRule(RelativeLayout.RIGHT_OF,cTVBot2.getId() );
          lpcTVBot3.addRule(RelativeLayout.CENTER_VERTICAL);      
          ibMenuBot.addView(cTVBot3, lpcTVBot3);      
  
          TextView cTVBot4 = new TextView(this);
          cTVBot4.setId(5004);        
          cTVBot4.setText("About Us");        
          cTVBot4.setTextColor(Color.rgb(179,116,197));
          cTVBot4.setTextSize(nTextH);
          cTVBot4.setTypeface(Typeface.create("arial", Typeface.NORMAL));
          cTVBot4.setPadding(ibMenuPadding,ibMenuPadding,ibMenuPadding,ibMenuPadding);
          RelativeLayout.LayoutParams lpcTVBot4= new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);       
          lpcTVBot4.addRule(RelativeLayout.RIGHT_OF,cTVBot3.getId() );
          lpcTVBot4.addRule(RelativeLayout.CENTER_VERTICAL);      
          ibMenuBot.addView(cTVBot4, lpcTVBot4);      
  
  
          // +++++++++++++ MIDDLE COMPONENT: all our GUI content
          LinearLayout midLayout = new LinearLayout (this);
          midLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
          midLayout.setOrientation(LinearLayout.VERTICAL);
          RelativeLayout.LayoutParams midParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
          midParams.addRule(RelativeLayout.ABOVE,ibMenuBot.getId());
          midParams.addRule(RelativeLayout.BELOW,ibMenu.getId());
          global_panel.addView(midLayout,midParams );
          //scroll - so our content will be scrollable between the header and the footer
          ScrollView vscroll = new ScrollView(this);
          vscroll.setId(6004);    
          vscroll.setFillViewport(false);
          midLayout.addView(vscroll);
  </code></pre>
  
  <p>//below code not working <strong><em>*</em>**<em>*</em>***</strong></p>
  
  <pre><code>            ListView maListViewPerso = (ListView) findViewById(vscroll.getId());
              ArrayList&lt;HashMap&lt;String, String&gt;&gt; listItem = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
              HashMap&lt;String, String&gt; map;     
              map = new HashMap&lt;String, String&gt;();
              map.put("titre", "Movie Ticket");
              map.put("description", "Movie Ticket Booking");
              map.put("img", String.valueOf(R.drawable.reel_icon));
              listItem.add(map);
  
  
  
              map = new HashMap&lt;String, String&gt;();
              map.put("titre", "Snow World");
              map.put("description", "SnowWorld Tickets");
              map.put("img", String.valueOf(R.drawable.reel_icon));
              listItem.add(map);
  
              map = new HashMap&lt;String, String&gt;();
              map.put("titre", "Kissing Car");
              map.put("description", "Kissing Car Tickets");
              map.put("img", String.valueOf(R.drawable.reel_icon));
              listItem.add(map);
  
              map = new HashMap&lt;String, String&gt;();
              map.put("titre", "Events");
              map.put("description", "Events in Mall");
              map.put("img", String.valueOf(R.drawable.reel_icon));
              listItem.add(map);
  
              map = new HashMap&lt;String, String&gt;();
              map.put("titre", "Screens");
              map.put("description", "Screens @ Abirami");
              map.put("img", String.valueOf(R.drawable.reel_icon));
              listItem.add(map);
  
  
              SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(), listItem, R.layout.main_menu_list,
                     new String[] {"img", "titre", "description"}, new int[] {R.id.img, R.id.titre, R.id.description});
  
  
              maListViewPerso.setAdapter(mSchedule);
  
  
  
  
          setContentView(global_panel);
      }
  
  
  }
  
  main_menu_list.xml
  ------------------
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      &gt;
  
      &lt;ImageView
          android:id="@+id/img"
  
          android:layout_gravity="center_vertical"
  
          android:padding="10px"
          android:layout_width="70dp"
          android:layout_height="70dp"/&gt;
          /&gt;
  
      &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="center_vertical"
          android:paddingLeft="10px"
              android:paddingRight="10px"
                      android:layout_weight="1"
          &gt;
  
          &lt;TextView android:id="@+id/titre"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:textSize="26px"
               android:textStyle="bold"
               /&gt;
  
          &lt;TextView android:id="@+id/description"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               /&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>