如何在页脚布局片段下方添加列表视图按钮 [英] How to add button in footer below listview in layout with fragment

查看:216
本文介绍了如何在页脚布局片段下方添加列表视图按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在页脚布局片段下面添加列表视图按钮。
我有code如下:

How to add button in footer below listview in layout with fragment. I have code as below:

在片段的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

/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

/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中看到的,我得到的信息错误的Andr​​oid运行在74行,行74是:

And i get error(Force Close), if i see in logcat, i get message error Android Runtime in line 74, line 74 is:

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

我的问题,我想在页脚添加按钮,下面列表视图。像作为这张截图
谢谢。

推荐答案

/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:layout_height="wrap_content"
        android:text="Load More" />

</LinearLayout>

这篇关于如何在页脚布局片段下方添加列表视图按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆