title: Android - ListActivity, add Header and Footer view
body: <p>I'm using ListActivity, listview.</p>
  
  <pre class="lang-java prettyprint-override"><code>listView = getListView();
  </code></pre>
  
  <p>just working perfectly. I added footer view as</p>
  
  <pre class="lang-java prettyprint-override"><code>LayoutInflater inflater = getLayoutInflater();
  listView.addFooterView( inflater.inflate( R.layout.footer, null ), null, false);
  </code></pre>
  
  <p>and everything was shiny but ugly, so i wanted to add this footer view (which contains only 1 edittext and only 1 button ) to header of listView as</p>
  
  <pre class="lang-java prettyprint-override"><code>LayoutInflater inflater = getLayoutInflater();
  listView.addHeaderView( inflater.inflate( R.layout.footer, null ), null, false);
  </code></pre>
  
  <p>and suddenly everything goes wrong, and i get RuntimeException immediately.</p>
  
  <pre class="lang-java prettyprint-override"><code>Suspended(exception RuntimeException)
  ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent)
  ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent)
  ActivityThread.access$2200(ActivityThread, Activity$ActiviyRecord, Intent),
  so on..
  </code></pre>
  
  <p>Why is it throws exception ? What is different between addFooterView and addHeaderView, and how can i add Header to ListActivity ?</p>
  
  <p>UPDATE</p>
  
  <p>So as you can read in comments, my logcat still doesn't work, but i just tried next at this moment: </p>
  
  <pre class="lang-java prettyprint-override"><code>} catch(Exception e){ 
    Writer result = new StringWriter(); 
    PrintWriter printWriter = new PrintWriter(result);
    e.printStackTrace(printWriter);
    String error = result.toString(); 
  }
  </code></pre>
  
  <p>and afterward i put breakpoint, and i can read error in expressions section. it said :
  </p>
  
  <pre><code>java.lang.IllegalStateException: Cannot add header view to list -- setAdapter has already been called. 
  </code></pre>
  
  <p>it was instructive for all of us. After change sort of commands, it works perferctly.</p>