title: Android: ListView with TextView header problem
body: <p>I have a main activity like :</p>
  
  <pre><code>public class TestActivity  extends Activity{
      List&lt;String&gt; users;
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.usersview);
          showList();
  
      }
      private void showList() {
          users=new ArrayList&lt;String&gt;();
          users.add("User1");
          users.add("User2");
          users.add("User3");
  
          ListView lv=(ListView)findViewById(R.id.listv);
  //      TextView tv=(TextView)findViewById(R.id.welcomeMsg);
  //      lv.addHeaderView(tv);
          lv.setAdapter( new ListArrAdapter(this, R.layout.userlist, users));
      }
  </code></pre>
  
  <p>ArrayAdapter :</p>
  
  <pre><code>public class ListArrAdapter extends ArrayAdapter&lt;String&gt; {
      private List&lt;String&gt; users;
      private Context context;
      private int listlayout;
  
      public ListArrAdapter(Context context, int textViewResourceId,
              List&lt;String&gt; users) {
          super(context, textViewResourceId, users);
          this.users = users;
          listlayout = textViewResourceId;
          this.context = context;
      }
      @Override
      public View getView(int position, View convertView, ViewGroup viewGroup) {
          String userName = users.get(position);
          if (null == convertView) {
              LayoutInflater inflater = (LayoutInflater) context
                      .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              convertView = inflater.inflate(listlayout, null);
          }
          TextView firstName = (TextView) convertView
                  .findViewById(R.id.firstNameTv);
          firstName.setText(userName);
          return convertView;
      }
  }
  </code></pre>
  
  <p>usersview layout :</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;TextView
          android:text="@string/header"
          android:id="@+id/welcomeMsg"
          android:textSize="30dp"
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;&lt;/TextView&gt;
      &lt;ListView
          android:layout_height="wrap_content"
          android:id="@+id/listv"
          android:layout_width="match_parent"&gt;&lt;/ListView&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>userlist layout for each items:</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:background="#EEFFEE"
      android:orientation="vertical"&gt;
      &lt;TextView
          android:id="@+id/firstNameTv"
          android:textSize="20dp"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"&gt;&lt;/TextView&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>My problem is : </p>
  
  <p>when i run this code only the welcome message is displayed(The items in list are not displayed). </p>
  
  <p>when i uncomment the lines</p>
  
  <pre><code>    TextView tv=(TextView)findViewById(R.id.welcomeMsg);
      lv.addHeaderView(tv);
  </code></pre>
  
  <p>in TestActivity, i get following exception</p>
  
  <pre><code>09-16 19:45:10.680: ERROR/AndroidRuntime(31044): Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
  </code></pre>
  
  <p>in line</p>
  
  <pre><code>lv.setAdapter( new ListArrAdapter(this, R.layout.userlist, users));
  </code></pre>
  
  <p>I want to display the list of users with a message-header on top. But i got these problem. Where is the problem and what is the solution.</p>