title: Adding an OnItemClickListener onto a header in a ListView in android
body: <p>I am trying to add an on click listener to a header in a listview. I can access the elements in the listview fine, but I cannot get access (nor even add a listener) onto the actual header. The reason for this is I would like my list to give a summary of the items in other lists, and if you click on a header it will direct to another screen that shows the full list. I thought maybe the index passed into the overridden onItemClick would give it as an index of 0 (being the first item in the list) but 0 is never passed in as an index; 1 is the lowest thing passed in and it is the first item in the list under the header. Here's what I mean:</p>
  
  <pre><code>public void onItemClick( final AdapterView&lt;?&gt; parent, final View item, 
                                 final int index, final long id) {
          switch(index)
          {
          case 0:
              Toast.makeText( this, "CLICKED ON HEADER", Toast.LENGTH_LONG).show();
              break;
          case 1:
              Toast.makeText( this, "Clicked on 1st item in list", Toast.LENGTH_LONG).show();
              ...
  </code></pre>
  
  <p>I also thought maybe I could add an icon to the header and add an on-click listener to the icon, but I keep getting a null-pointer:</p>
  
  <pre><code>    favorites_list_view = (ListView) findViewById ( R.id.main_favorite_view );
      FavoritesAdapter adapter = new FavoritesAdapter( (Context)this, favoriteData );
  
      View header = (View)getLayoutInflater().inflate( 
                                            R.layout.list_header_with_icon, null );
      TextView headerTitle = (TextView)header.findViewById( R.id.main_header_text );
      headerTitle.setText( "Top Favorites" );
      headerIcon = (ImageButton)findViewById( R.id.main_header_icon );
      headerIcon.setOnClickListener( (OnClickListener)this );
      favorites_list_view.addHeaderView( header );
  
      favorites_list_view.setAdapter( adapter );
      favorites_list_view.setOnItemClickListener( (OnItemClickListener)this );
  </code></pre>
  
  <p>It doesn't work even if I move the setting of the header listener later. Any ideas?</p>