title: Android Multiline ListView with Headings
body: <p>I need to create a <code>ListView</code> in Android that has headers and is multiline. I use this to display the assignment title and the due date below it. The assignments are sorted under two headers: "Upcoming Assignments" and "Past Assignments" (based on date, of course).  </p>
  
  <p>I have the headers working and the assignment title displaying properly, but I am stumped as to how to incorporate a second line into the list.</p>
  
  <p>Here is my code:  </p>
  
  <p>ListCourseAssignments.java</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState){
      super.onCreate(savedInstanceState);
      final SeparatedListAdapter adapter;
      setContentView(R.layout.courseassignmentslistview);
      adapter = new SeparatedListAdapter(getContext());
      ArrayAdapter&lt;String&gt; upcomingList = new ArrayAdapter&lt;String&gt;(getContext(), R.layout.list_item, Homework.getUpcomingDates()); // Homework.getUpcomingDates() Returns string array
      ArrayAdapter&lt;String&gt; pastList = new ArrayAdapter&lt;String&gt;(getContext(), R.layout.list_item, Homework.getPastDates()); // Homework.getPastDates() Returns string array
  
      adapter.addSection("Upcoming Assignments", upcomingList); 
      adapter.addSection("Past Assignments", pastList);
  
      ListView lv = (ListView) findViewById(android.R.id.list);
      lv.setAdapter(adapter);
  
      lv.setOnItemClickListener(new OnItemClickListener(){
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long duration){
              String item = (String) adapter.getItem(position);
              Toast.makeText(getApplicationContext(), item, Toast.LENGTH_SHORT).show();
          }
      });
  }
  </code></pre>
  
  <p>SeparatedListAdapter.java</p>
  
  <pre><code>public class SeparatedListAdapter extends BaseAdapter {
  public final Map&lt;String, Adapter&gt; sections = new LinkedHashMap&lt;String, Adapter&gt;();
  public final ArrayAdapter&lt;String&gt; headers;
  
  public SeparatedListAdapter(Context context) {
      headers = new ArrayAdapter&lt;String&gt;(context, R.layout.courseassignmentslistview_header);
  }
  
  public void addSection(String section, Adapter adapter) {
      this.headers.add(section);
      this.sections.put(section, adapter);
  }
  
  public Object getItem(int position) {
      for (Object section : this.sections.keySet()) {
          Adapter adapter = sections.get(section);
          int size = adapter.getCount() + 1;
  
          if (position == 0) return section;
          if (position &lt; size) return adapter.getItem(position - 1);
  
          position -= size;
      }
      return null;
  }
  
  public int getCount() {
      int total = 0;
      for (Adapter adapter : this.sections.values()) total += adapter.getCount() + 1;
      return total;
  }
  
  @Override
  public int getViewTypeCount() {
      int total = 1;
      for (Adapter adapter : this.sections.values()) total += adapter.getViewTypeCount();
      return total;
  }
  
  @Override
  public int getItemViewType(int position) {
      int type = 1;
      for (Object section : this.sections.keySet()) {
          Adapter adapter = sections.get(section);
          int size = adapter.getCount() + 1;
  
          if (position == 0) return 0;
          if (position &lt; size) return type + adapter.getItemViewType(position - 1);
  
          position -= size;
          type += adapter.getViewTypeCount();
      }
      return -1;
  }
  
  public boolean areAllItemsSelectable() {
      return false;
  }
  
  @Override
  public boolean isEnabled(int position) {
      return (getItemViewType(position) != 0);
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      int sectionnum = 0;
      for (Object section : this.sections.keySet()) {
          Adapter adapter = sections.get(section);
          int size = adapter.getCount() + 1;
  
          if (position == 0) return headers.getView(sectionnum, convertView, parent);
          if (position &lt; size) return adapter.getView(position - 1, convertView, parent);
  
          position -= size;
          sectionnum++;
      }
      return null;
  }
  
  @Override
  public long getItemId(int position) {
      return position;
  }
  }
  </code></pre>
  
  <p>courseassignmentslistview_header.xml</p>
  
  <pre><code>&lt;TextView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/list_header_title"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:paddingTop="2dip"
      android:paddingBottom="2dip"
      android:paddingLeft="5dip"
      style="?android:attr/listSeparatorTextViewStyle" /&gt;
  </code></pre>
  
  <p>courseassignmentslistview.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
  
      &lt;ListView
          android:id="@+android:id/list"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>listitem.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TextView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:padding="10dp"
      android:textSize="16sp" &gt;
  &lt;/TextView&gt;
  </code></pre>
  
  <p><a href="http://postimage.org/image/3qb6384yl/" rel="nofollow">Here's a screenshot of what it currently looks like.</a></p>
  
  <p>EDIT: I know how to create a list with multiline, but I just don't know how to put it together with a list with headers (such as this)...</p>