gpt4 book ai didi

java - 膨胀异常 : cant inflate custom listview from a pinnedheaderlistview library

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

我正在尝试实现一个名为 PinnedHeaderListView 的库在我的 fragment 中为我的 ListView 设置一个固定标题。

这就是我想出的

public class MyFragment extends Fragment{

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.main, container, false);

PinnedHeaderListView listview= (PinnedHeaderListView) v.findViewById(R.id.pinnedListView);
MyFragmentAdapter adapter = new MyFragmentAdapter ();


LinearLayout header1 = (LinearLayout)inflater.inflate(R.layout.list_item, null);
((TextView) header1.findViewById(R.id.textItem)).setText("HEADER 1");

LinearLayout header2 = (LinearLayout) inflater.inflate(R.layout.list_item, null);
((TextView) header2.findViewById(R.id.textItem)).setText("HEADER 2");

LinearLayout footer = (LinearLayout) inflater.inflate(R.layout.list_item, null);
((TextView) footer.findViewById(R.id.textItem)).setText("FOOTER");

listview.addHeaderView(header1);
listview.addHeaderView(header2);
listview.addFooterView(footer);

comicList.setAdapter(adapter);

return v;
}

}

我尽可能地尝试按照图书馆的例子。我唯一改变的是我在 fragment 上实现它。这是我的 main.xml 导致 InflateException
    <?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<za.co.immedia.pinnedheaderlistview.PinnedHeaderListView
android:id="@+id/pinnedListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">

</za.co.immedia.pinnedheaderlistview.PinnedHeaderListView>

</LinearLayout>

其他布局工作正常。

这是错误:
FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #8: Error inflating class za.co.immedia.pinnedheaderlistview.PinnedHeaderListView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)

我不知道问题出在哪里,我添加了库,编译没有错误,但运行时崩溃。有什么建议吗?

最佳答案

清理你的项目,
然后右键单击您的项目并转到 android 工具并单击修复项目属性。
并再次运行该程序。

关于java - 膨胀异常 : cant inflate custom listview from a pinnedheaderlistview library,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19874001/

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