gpt4 book ai didi

android - 尝试向 ListView 添加页脚时出现 ClassCastException

转载 作者:行者123 更新时间:2023-11-30 02:49:17 25 4
gpt4 key购买 nike

我正在尝试向 ListView 添加页脚,但出现以下错误:

06-30 03:57:27.545: E/AndroidRuntime(10112): java.lang.ClassCastException: 
android.view.ViewGroup$LayoutParams cannot be cast to
android.widget.AbsListView$LayoutParams

这是我的 ListView 的页脚 (listview_footer.xml):

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="7dip"
android:paddingBottom="7dip"
android:orientation="horizontal"
android:gravity="center">

<ImageButton
android:id="@+id/addButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginTop="12dp"
android:src="@drawable/add_button" />

</LinearLayout>

下面是我用来将页脚添加到 ListView 的代码:

View footerView = inflater.inflate(R.layout.listview_footer, null, false);  

addButton = (ImageButton) footerView.findViewById(R.id.addButton);

listView.addFooterView(footerView);

在这一行:

View footerView = inflater.inflate(R.layout.listview_footer, null, false);

“null”参数在 Eclipse 中显示为下方有一条橙色线,当我将鼠标悬停在它上面时,它显示:

Avoid passing null as the view root (needed to resolve layout 
parameters on the inflated layout's root element)

在这种情况下,我不确定应该将什么指定为第二个参数(ViewGroup 根)。

最佳答案

我认为你必须更换

View footerView = inflater.inflate(R.layout.listview_footer, null, false);

View footerView = inflater.inflate(R.layout.listview_footer, listview, false);

这样充气机就会给它正确的布局参数

关于android - 尝试向 ListView 添加页脚时出现 ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24485568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com