Android 如何在水平列表视图中添加页脚按钮

Android 如何在水平列表视图中添加页脚按钮,android,listview,footer,Android,Listview,Footer,我想在listview的页脚添加一个按钮,我使用的是水平listview,适配器类: public ItemAdapter(Context context, int layout, Cursor c,String[] from, int[] to) { super(context, layout, c, from, to,0); this.layout = layout; inflator= LayoutInflater.from(context)

我想在listview的页脚添加一个按钮,我使用的是水平listview,适配器类:

public ItemAdapter(Context context, int layout, Cursor c,String[] from, int[] to) {
        super(context, layout, c, from, to,0);
        this.layout = layout;
        inflator= LayoutInflater.from(context);

    }
我返回newView和bindView:

    public View newView(Context context, Cursor cursor, ViewGroup parent) {     
        View v = inflator.inflate(layout, parent, false);
        TextView footer = (TextView)v.findViewById(R.id.bAdd);
        return v;

    }

    @Override
    public void bindView(View v, final Context context, Cursor c) {
        final int id = c.getInt(c.getColumnIndex(ItemDb.ID));
        final String name = c.getString(c.getColumnIndex(ItemDb.NAME));
        }
活动课:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);     
        String[] from = new String[] { ItemDb.NAME, ItemDb.CONDITION, ItemDb.EMAIL};
        int[] to = new int[] { R.id.etItemName, R.id.etItemCondition, R.id.etEmail };
        itemAdapter = new ItemAdapter(this,R.layout.list_item, null, from, to);
        this.setListAdapter(itemAdapter);
    }
如何在listview页脚中添加按钮? 这是我的xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/photo"
        android:layout_width="85dp"
        android:layout_height="85dp"
        android:background="@drawable/photo_frame"
        android:contentDescription="@string/imagedescription"
        android:src="@drawable/ic_launcher" >
    </ImageView>


    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/condition"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/name"
            android:layout_marginLeft="10dp"
            android:text="@string/condition"
            android:textColor="#000"
            android:textSize="14sp" />

        <TextView
            android:id="@+id/email"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/condition"
            android:layout_marginLeft="10dp"
            android:text="@string/email"
            android:textColor="#000"
            android:textSize="14sp" />

    </RelativeLayout>

</LinearLayout>

  • 重写listview适配器的
    getCount()
    ,以返回
    data.size()+1
    元素
  • 在getView()中插入如下内容:

    if(position==data.size()){ 返回getFooterView();
    }


  • getFooterView()
    中,使用按钮为适当的布局充气。

    另外,看看这个线程:哈哈,我只是想说我不太明白你的意思。。谢谢你的额外链接,我试着先学习^^但我完全不使用listview,如何应用listview.addFooterView(footer);就我而言我只有一个xml。不明白你的意思,在你提到的vogella链接中有一个例子,这对你不适用吗。。或者我不知道如何在我的案例中应用,因为它似乎与我的案例有点不同,我只使用一个xml来添加行水平listview。