title: Adding Custom Header to List Fragment in Android
body: <p>I am trying to add a custom header that isnt clickable but will have a checkbox that will "check all" checkboxes under it.  </p>
  
  <p>This is my List Fragment</p>
  
  <pre><code>public class AssesmentListFragment extends ListFragment {
  
  private static String BUNDLE_KEY_APPLICATION = "LIST_ITEM";
  FastAssesmentListAdapter adapter;
  View listHeader;
  
  public AssesmentListFragment() {}
  
  public AssesmentListFragment(Data[] data) {
  
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);     
  
      Data[] assestments = {new Data("Assesment ID","Name", "Date"), new Data("123456", "Assestment 2", "9/12/12"),
              new Data("345672", "Assesment 3", "9/13/12"), new Data("566893", "Assesment 4", "9/14/12")};
  
              //This is the part that makes the app crash
      View header = getActivity().getLayoutInflater().inflate(R.layout.list_adapter_assesments, null);
      ListView listView = getListView();
      listView.addHeaderView(header);
  
      adapter = new FastAssesmentListAdapter(getActivity(), assestments);
      setListAdapter(adapter);
  
      updateList(assestments);
  }
  
  
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
  
  }
  private void updateList(Data[] assestments) {
      // NOTE: addAll is not being used to support pre-honeycomb devices
  
      synchronized(adapter) {
          adapter.clear();
          adapter.addAll(assestments);
          adapter.notifyDataSetChanged();
      }
  }
  
  @Override
  public void onListItemClick(ListView parentView, View selectedItemView, int position, long id) {
      String model = (String) parentView.getItemAtPosition(position);
      ((FacilityActivity) getActivity()).onItemSelected(model);
  
  }
  
  @Override
  public void onSaveInstanceState(Bundle outState) {
      super.onSaveInstanceState(outState);
      //outState.putInt("curChoice", mCurCheckPosition);
    } 
   }
  </code></pre>
  
  <p>This is the layout I am trying to use for header</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="fill_parent"
      android:layout_height="wrap_content" 
      android:orientation="vertical"&gt;
  
  &lt;LinearLayout 
      android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:paddingLeft="25dp"
  android:paddingRight="10dp"
  android:orientation="horizontal"&gt; 
  
  &lt;TextView android:id="@+id/adapter_header_textview_column1"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="4"
      android:textColor="@color/defaultTextColor"
      android:textAppearance="?android:attr/textAppearanceLarge"
      android:textSize="28sp"
      android:text="Assesment ID" /&gt;
  
  &lt;TextView android:id="@+id/adapter_header_textview_column2"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="4"
      android:textColor="@color/defaultTextColor"
      android:textAppearance="?android:attr/textAppearanceLarge"
      android:textSize="28sp"
      android:text="Name" /&gt;
  
  &lt;TextView android:id="@+id/adapter_header_textview_column3"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="3"
      android:textColor="@color/defaultTextColor"
      android:textAppearance="?android:attr/textAppearanceLarge"
      android:textSize="28sp" 
      android:text="Date"/&gt;
  
  &lt;CheckBox
      android:id="@+id/header_check_box"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:color="@color/defaultTextColor"
      android:layout_weight=".5"
      android:gravity="center" /&gt;
  &lt;/LinearLayout&gt;
  &lt;View
      android:layout_width="fill_parent"
      android:layout_height="5dp"
      android:background="@color/BPGreenColor" /&gt; 
  &lt;ListView
   android:id="@android:id/list"
   android:layout_width="match_parent"
   android:layout_height="wrap_content" &gt;
  &lt;/ListView&gt; 
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Then this is the array adapter I am using: </p>
  
  <pre><code>public class FastAssesmentListAdapter extends ArrayAdapter&lt;Data&gt; {
  
      private static int LAYOUT_ID = R.layout.list_adapter_with_checkbox_three_column;
  private final Data[] assesments;
  private final Context context;
  LinearLayout listHeader;
  
  static class ViewHolder {
      protected TextView column1;
      protected TextView column2;
      protected TextView column3;
      protected CheckBox checkbox;
  }
  
  public FastAssesmentListAdapter(Context context, Data[] assesments) {
      super(context, LAYOUT_ID, assesments);
      this.context = context;
      this.assesments = assesments;
  }
  
  //ListFragment and array adapter will automatically call this over and over to auto populate the list
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      final Data item = getItem(position);
  
      // Formulate row view (create if it does not exist yet)
      View view = convertView;
      if(view == null) {
          LayoutInflater inflater = ((Activity) getContext()).getLayoutInflater();
          view = inflater.inflate(LAYOUT_ID, null);
          final ViewHolder viewHolder = new ViewHolder();
          viewHolder.column1 = (TextView) view.findViewById(R.id.adapter_textview_column1);
          viewHolder.column2 = (TextView) view.findViewById(R.id.adapter_textview_column2);
          viewHolder.column3 = (TextView) view.findViewById(R.id.adapter_textview_column3);
          viewHolder.checkbox = (CheckBox) view.findViewById(R.id.check_box);
          view.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                  Toast.makeText(getContext(), "Clicked",
                          Toast.LENGTH_SHORT).show();
                  Intent intent = new Intent(getContext(), FacilityActivity.class);
                  getContext().startActivity(intent);
              }
          });
              if(viewHolder.checkbox != null) {
                  viewHolder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  
                      @Override
                      public void onCheckedChanged(CompoundButton buttonView,
                          boolean isChecked) {
                        if(isChecked) {
                            item.setSelected(isChecked);
                            Toast.makeText(getContext(), "Checked",
                                    Toast.LENGTH_SHORT).show();
                        }
  
                      }
                    });
              }
          view.setTag(viewHolder);
          viewHolder.checkbox.setTag(position);
      }
      ViewHolder viewHolder = (ViewHolder) view.getTag();
      viewHolder.checkbox.setTag(position);
      viewHolder.column1.setText(item.getColumn1());
      viewHolder.column2.setText(item.getColumn2());
      viewHolder.column3.setText(item.getColumn3());
      viewHolder.checkbox.setChecked(item.isSelected());
  return view;
  }
   }
  </code></pre>
  
  <p>on a side note, the onlistitemclicked in the fragment doesnt work, i have to set a listener in the adapter and then it works. any ideas on that? but mainly I need to figure out how to use a custom header and custom rows in the list view.  Here is the layout for the rows</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="fill_parent"
  android:layout_height="wrap_content"
  android:paddingLeft="25dp"
  android:paddingRight="10dp"
  android:orientation="horizontal"&gt; 
  
  &lt;TextView android:id="@+id/adapter_textview_column1"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="4"
      android:textAppearance="?android:attr/textAppearanceLarge"
      android:textSize="25sp" /&gt;
  
  &lt;TextView android:id="@+id/adapter_textview_column2"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="4"
      android:textAppearance="?android:attr/textAppearanceLarge"
      android:textSize="25sp" /&gt;
  
  &lt;TextView android:id="@+id/adapter_textview_column3"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="3"
      android:textAppearance="?android:attr/textAppearanceLarge"
      android:textSize="25sp" /&gt;
  
  &lt;CheckBox
      android:id="@+id/check_box"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_weight=".5"
      android:gravity="center" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>