1

我正在尝试添加一个显示在列表视图底部的按钮,因为它将是一个加载更多按钮...该按钮未显示。

ListAdapter adapter = new SimpleAdapter(this, contactList,R.layout.list_item,
        new String[] { TAG_NAME, TAG_EMAIL, TAG_PHONE_MOBILE }, new int[] {
                R.id.name, R.id.email, R.id.mobile });

setListAdapter(adapter);

// selecting single ListView item
ListView lv = getListView();
// Getting listview from xml


// Creating a button - Load More
Button btnLoadMore = new Button(this);
btnLoadMore.setText("Load More");
lv.addFooterView(btnLoadMore);

这是 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="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>

已解决:我需要在设置适配器之前执行此操作

    ListAdapter adapter = new SimpleAdapter(this, contactList,R.layout.list_item,
            new String[] { TAG_NAME, TAG_EMAIL, TAG_PHONE_MOBILE }, new int[] {
                    R.id.name, R.id.email, R.id.mobile });
    lv = getListView();
    // Creating a button - Load More
    Button btnLoadMore = new Button(this);
    btnLoadMore.setText("Load More");
    lv.addFooterView(btnLoadMore);
    setListAdapter(adapter);
4

0 回答 0