android列表视图页脚未显示

时间:2014-06-24 05:14:56

标签: android android-listview

我将列表项添加到列表视图中,如

如果我有50个列表项,我将加载前10个项目,然后剩余10个项目,依此类推......

你可以在这里找到一些代码部分以表示敬畏......

itemsPerPage=10;
list = (ListView) findViewById(R.id.list1);
 footerView = ((LayoutInflater) this
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
                    R.layout.footer, null, false);
list.addFooterView(footerView); 
adapter.addAll(getItemsBetween(0, itemsPerPage));// Loading first 10 Items

这是我的滚动代码......

 list.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem,
                int visibleItemCount, int totalItemCount) {

                if (totalItemCount <= totalCount) {
                    // what is the bottom iten that is visible
                    int lastInScreen = firstVisibleItem + visibleItemCount;

                    if ((lastInScreen == totalItemCount)){


                        int currentItemCount= mostViewdAdapter.getCount();

                        mostViewdAdapter.addAll(getItemsBetween(currentItemCount, currentItemCount+itemsPerPage));
                        mostViewdAdapter.notifyDataSetChanged();
                    }


                }else{
                    System.out.println("End of the list view reached");
                    footerView.setVisibility(View.GONE);

                }




        }
    });

我在这里分享我的页脚XML:     

<ProgressBar
    android:id="@+id/footerBar"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:gravity="center" />

<TextView
    android:id="@id/android:empty"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:padding="5dp"
    android:text="Loading..." />

3 个答案:

答案 0 :(得分:1)

    Have a look at following code
    1) Add custom_listview_footer.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="wrap_content"
        android:gravity="center"
        android:orientation="horizontal"
        android:paddingBottom="7dip"
        android:paddingTop="7dip" >

        <Button
            android:id="@+id/btn_Invite"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_weight="0"
            android:text="Load More"
            android:textAppearance="?android:attr/textAppearanceLarge"
             />

    </LinearLayout>

2) In your activity  call 
      View footerView = ((LayoutInflater) _con
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
                    R.layout.custom_listview_footer, null, false);
3) Call Button of the footer view
Button btnInvite = (Button) footerView.findViewById(R.id.btn_Invite);

4) Lastly Add footer to the listview

lvPhnContacts.addFooterView(footerView);

答案 1 :(得分:0)

您可以发布有关何时致电Listview.setAdapter()的更多代码? 在将适配器设置为列表视图之前,应该调用addFooterView()

答案 2 :(得分:0)

尝试以下代码。

itemsPerPage=10;
list = (ListView) findViewById(R.id.list1);
 footerView = ((LayoutInflater) this
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
                    R.layout.footer, null, false);
list.addFooterView(footerView); 
adapter.addAll(getItemsBetween(0, itemsPerPage));// Loading first 10 Items
// after set footer
list.setAdapter(your adapter);//set adapter 


list.setOnScrollListener(new OnScrollListener() {
    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem,
                int visibleItemCount, int totalItemCount) {

       final int lastItem = firstVisibleItem + visibleItemCount;
       if(lastItem == totalItemCount) {
           //load more data
           // footerView visible
       }
    }
});