如何在带有片段的布局中的列表视图下方的页脚中添加按钮。我有如下代码:
在片段 java.
ListView listview;
Button button;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.category, container, false);
View footerView = inflater.inflate(R.layout.footer_category, null);
listview = (ListView) view.findViewById(R.id.categoryNewsItemGrid);
listview.addFooterView(footerView);
loadmore = (Button) footerView.findViewById(R.id.loadMore);
loadmore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Log.d("Mylog","Button can click");
}
});
return view;
}
/res/layout/category.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/categoryNewsItemGrid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#C5C5C5"
android:dividerHeight="2px" />
</LinearLayout>
/res/layout/footer_category.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/footerCategory"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/loadMore"
android:layout_width="fill_parent"
android:text="Load More" />
</LinearLayout>
我得到错误(强制关闭),如果我在 logcat 中看到,我在第 74 行收到消息错误 Android 运行时,第 74 行是:
View footerView = inflater.inflate(R.layout.footer_category, null);
我的问题,我想在列表视图下方的页脚中添加按钮。就像这个截图一样。谢谢。