getListView().addFooterView(视图)在Android 2.2中不工作
下面是我的getListView().addFooterView(视图)在Android 2.2中不工作,android,listview,android-listview,Android,Listview,Android Listview,下面是我的公共类AnalListFragment扩展ListFragment类中的代码 public void addFooterLoader() { Parcelable state = getListView().onSaveInstanceState(); setListAdapter(null); LayoutInflater factory = LayoutInflater.from(getActivity()); View loaderView =
公共类AnalListFragment扩展ListFragment
类中的代码
public void addFooterLoader() {
Parcelable state = getListView().onSaveInstanceState();
setListAdapter(null);
LayoutInflater factory = LayoutInflater.from(getActivity());
View loaderView = factory.inflate(R.layout.list_more_content_footer, null);
getListView().addFooterView(loaderView); // EXCEPTION HERE
setAdapterData();
getListView().onRestoreInstanceState(state);
}
布局文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
android:layout_width="48dp"
android:layout_height="48dp" />
</RelativeLayout>
我不知道出了什么问题以及为什么它不能在2.2设备上工作。您是否尝试删除这一行:
setListAdapter(null)
Hm,我认为它不应该工作,因为文档中说“只能在设置适配器之前调用此方法”,关于addFooterView()
。但它帮助了我。你能给我解释一下这个文档问题吗?老实说,我从来没有遇到过这个问题。答案来自它的逻辑。当您将适配器设置为null时,您的意思是listview有一个null适配器,并且logCat中的错误表明adapterView中有一个null错误。这意味着在你的适配器是空的;在本例中,您的适配器。
12-09 15:57:07.861: E/AndroidRuntime(10621): FATAL EXCEPTION: main
12-09 15:57:07.861: E/AndroidRuntime(10621): java.lang.NullPointerException
12-09 15:57:07.861: E/AndroidRuntime(10621): at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:778)
12-09 15:57:07.861: E/AndroidRuntime(10621): at android.widget.ListView.addFooterView(ListView.java:421)
12-09 15:57:07.861: E/AndroidRuntime(10621): at android.widget.ListView.addFooterView(ListView.java:436)
12-09 15:57:07.861: E/AndroidRuntime(10621): at com.example.analytics.AnalListFragment.addFooterLoader(AnalListFragment.java:150)