title: Android: xml layout for a listview with different items
body: <p>I'm reading this tutorial <a href="http://android.amberfog.com/?p=296" rel="noreferrer">http://android.amberfog.com/?p=296</a> . I'd like to create a Listview weith different types of rows. I understand how to create the adapter, but what about the xml layout? So I definire an xml layout like this one:</p>
  
  <p></p>
  
  <pre><code>&lt;ListView/&gt;
  
  &lt;TextView android:id="@+id/id1" /&gt;
  
  &lt;TextView android:id="@+id/id2" /&gt;
  
  &lt;ImageView android:id="@+id/id3" /&gt;
  
  &lt;TextView android:id="@+id/id4" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>Will it be a problem (for performance) if maybe one row uses just some elements (only some textviews) of the layout and another row maybe uses other elements? I don't understand if mine is the right way to define the xml or if I have to create different layout for each type of row.</p>
  
  <p>Thank you in advance </p>
  
  <p>EDIT: now I'm having a null point exception.</p>
  
  <p>java code from the adapter:</p>
  
  <pre><code>@Override
  
  public View getView(int position, View convertView, ViewGroup parent) {
  
  ViewHolder holder = null;
  int type = getItemViewType(position);
  
  if (convertView == null) {
      holder = new ViewHolder();
  
      convertView = mInflater.inflate(R.layout.listview_main, null);
      holder.textView_title = (TextView)convertView.findViewById(R.id.listview1);
  
      convertView.setTag(holder);
  } else {
      holder = (ViewHolder)convertView.getTag();
  }
  
  **holder.textView_title.setText("aaaa");** //NULL POINT EXCEPTION HERE
  
  return convertView;
  </code></pre>
  
  <p>}</p>
  
  <pre><code>class ViewHolder {
      public TextView textView_title;
  }
  </code></pre>
  
  <p>xml 1:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/main_layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:gravity="left"
                android:layout_margin="0dp"&gt;
  
      &lt;!-- android:background="#0094ff" --&gt;
  
      &lt;ListView
              android:id="@id/android:list"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:fastScrollEnabled="true"
              android:scrollbarStyle="insideInset"
              android:textFilterEnabled="false"
              android:divider="@null"
              android:layout_margin="0dp"
              android:paddingTop="0dp"
              android:paddingBottom="0dp"
              android:paddingLeft="15dp"
              android:paddingRight="22dp"/&gt;
  
  
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>xml2</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"
      android:gravity="left"
      android:layout_margin="0dp"&gt;
  
      &lt;TextView
          android:id="@+id/listview1"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:paddingTop="7dp"
          android:paddingBottom="0dp"
          android:paddingLeft="0dp"
          android:paddingRight="0dp"
          android:textSize="18sp"
          android:textColor="#000000"
          android:lines="1"&gt;
      &lt;/TextView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>