我有兩個ListFragments由tabhost maganned。 Firt time我切換標籤都沒關係。 headerView被正確添加。第二次我切換片段之間我得到這個執行:ListFragment添加headerView給出java.lang.IllegalStateException:alled
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.chiesacattolica.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)
和應用程序崩潰。我用來添加標題視圖的代碼如下:
@Override
public void onActivityCreated(Bundle arg0) {
super.onActivityCreated(arg0);
getListView().setOnScrollListener(this);
getListView().addHeaderView(searchBox);
setListAdapter(mAdapter);
}
有什麼不對?在此先感謝
這裏試試我的答案在http://stackoverflow.com/a/31181366/4489494希望這將有助於你.. –