我正在尝试在我的片段中实现一个名为PinnedHeaderListView的库,以便为我的列表视图提供一个 Pinned 标题。
这就是我想出的
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;
}
}
我尽可能地尝试按照图书馆的例子。我唯一改变的是我在片段上实现它。这是我的 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)
我不知道问题出在哪里,我添加了库,编译没有错误,但运行时崩溃。有什么建议吗?