hello there, I ve two ListFragments maganed by a tabhost. Firt time I switch between tab all is alright. The headerView is correctly added. The second time I switch between fragment I get this execption:
10-05 15:15:01.585: ERROR/AndroidRuntime(23263): java.lang.IllegalStateException: Cannot add header view to list -- setAdapter has already been called. 10-05 15:15:01.585: ERROR/ AndroidRuntime(23263): at android.widget.ListView.addHeaderView(ListView.java:261) 10-05 15:15:01.585: ERROR/AndroidRuntime(23263): at android.widget.ListView.addHeaderView(ListView.java:284) 10-05 15:15:01.585: ERROR/AndroidRuntime(23263): at it.mypackage.archive.ArchiveFragment.onActivityCreated(ArchiveFragment.java: 199) 10-05 15:15:01.585: ERROR/AndroidRuntime(23263): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java: 858) 10-05 15:15:01.585: ERROR/AndroidRuntime(23263): at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java: 1183) and the app crashes. The code I use to add the header view follows: @Override public void onActivityCreated(Bundle arg0) { super.onActivityCreated(arg0); getListView().setOnScrollListener(this); getListView().addHeaderView(searchBox); setListAdapter(mAdapter); } I manage to fix (??) setting the list adapter to null befor adding the header view but it does not seems a good thing to me. @Override public void onActivityCreated(Bundle arg0) { super.onActivityCreated(arg0); setListAdapter(null); getListView().setOnScrollListener(this); getListView().addHeaderView(searchBox); setListAdapter(mAdapter); } Adding footer instead I have the following crash: 10-09 18:45:13.866: ERROR/AndroidRuntime(18191): java.lang.NullPointerException 10-09 18:45:13.866: ERROR/AndroidRuntime(18191): at android.widget.AdapterView $AdapterDataSetObserver.onChanged(AdapterView.java:778) 10-09 18:45:13.866: ERROR/AndroidRuntime(18191): at android.widget.ListView.addFooterView(ListView.java:346) 10-09 18:45:13.866: ERROR/AndroidRuntime(18191): at android.widget.ListView.addFooterView(ListView.java:361) 10-09 18:45:13.866: ERROR/AndroidRuntime(18191): at it.mypackage.category.CategorySearchFragment.onActivityCreated(CategorySearchFragment.java: 131) 10-09 18:45:13.866: ERROR/AndroidRuntime(18191): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java: 858) 10-09 18:45:13.866: ERROR/AndroidRuntime(18191): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java: 1041) 10-09 18:45:13.866: ERROR/AndroidRuntime(18191): at android.support.v4.app.BackStackRecord.popFromBackStack(BackStackRecord.java: 687) 10-09 18:45:13.866: ERROR/AndroidRuntime(18191): at android.support.v4.app.FragmentManagerImpl.popBackStackState(FragmentManager.java: 1392) 10-09 18:45:13.866: ERROR/AndroidRuntime(18191): at android.support.v4.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java: 438) 10-09 18:45:13.866: ERROR/AndroidRuntime(18191): at android.support.v4.app.FragmentActivity.onBackPressed(FragmentActivity.java: 156) in order to add the footer I run the following snippet @Override public void onActivityCreated(Bundle arg0) { super.onActivityCreated(arg0); setListAdapter(null); getListView().setOnScrollListener(this); getListView().addHeaderView(searchBox); if (footer != null) { getListView().addFooterView(footer); } setListAdapter(mAdapter); } What am I doing wrong? -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en