I encounter a problem when I try to add a header on the List of my ListFragment. I heard I had to add the header view before the setListAdapter (I followed this topic Best place to addHeaderView in ListFragment ) and yet, it still doesn't work.
Here is my code :
@Override
public void onActivityCreated (Bundle savedInstanceState)
{
Log.i(General.TAG, "beginning of onActivityCreated");
super.onActivityCreated(savedInstanceState);
if (mheaderView != null) this.getListView().addHeaderView(getView().findViewById(R.layout.header)); // <= mheaderView is not null
ListView lv = getListView(); // <= lv is not null
lv.setAdapter(adapter);
Log.i(General.TAG, "end of onActivityCreated");
}
The stack trace generated on line "lv.setAdapter(adapter)"
is this one :
02-06 16:16:37.226: E/AndroidRuntime(25838): **java.lang.NullPointerException**
02-06 16:16:37.226: E/AndroidRuntime(25838): at android.widget.ListView.clearRecycledState(ListView.java:497)
02-06 16:16:37.226: E/AndroidRuntime(25838): at android.widget.ListView.resetList(ListView.java:483)
02-06 16:16:37.226: E/AndroidRuntime(25838): at android.widget.ListView.setAdapter(ListView.java:426)
02-06 16:16:37.226: E/AndroidRuntime(25838): at fr.pack.DetailFragment.onActivityCreated(DetailFragment.java:75)
But the adapter is not null, neither is the mHeaderView. Do you have any clue of the mistake I may have done ? Thanks in advance !