0

我想在列表视图的页脚添加一个按钮,我正在使用水平列表视图,适配器类

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);
    }

如何在列表视图页脚中添加按钮?这是我的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>
4

1 回答 1

0
  1. 覆盖getCount()列表视图适配器以返回data.size()+1元素;
  2. 在 getView() 中插入如下内容:

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

getFooterView()按钮膨胀适当的布局。

于 2013-06-03T15:00:34.240 回答