如何在Android中删除页脚视图?

时间:2016-04-25 05:16:08

标签: android pagination

我有三个按钮,我按钮显示分页。如果我点击按钮1调用分页,如果点击按钮2开始分页2,如果点击按钮3开始分页3它全部工作。我在每个分页的listView setOnScrollListener末尾添加了进度条。

但问题是每当进入列表末尾时,每次都会添加查看进度条。我尝试删除最后一页的页脚视图,然后获得inValid index out of bound exception index 0的例外。

有人可以帮助我如何正确地使用进度条进行分页。

1st button click = Pegination();
same as to 2nd button click =LoginUser_PostLoacalPages();
And same as to 3rd button click = R_Post_Pagination();


    Here is 1st pagination 


public void Pegination() {

            final int activityCount  = sharedPreferences.getInt("ActivityListCount", 0);
            Log.e("","activityCount in Pegination method ="+activityCount);

            footer = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.prohressbar, listView, false);
            rLayout = (RelativeLayout) footer.findViewById(R.id.progressRel);
            progressBar = (ProgressBar) footer.findViewById(R.id.progressBar);
            btnLoadMore = (Button) footer.findViewById(R.id.btnLoadMore);
            btnLoadMore.getLayoutParams().height = 0;
            progressBar.getLayoutParams().height = 130;
            btnLoadMore.setVisibility(View.GONE);
            progressBar.setVisibility(View.VISIBLE);
            listView.addFooterView(footer);

    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        private int total;

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

        @Override
        public void onScroll(AbsListView absListView, int firstItem, int visibleItemCount, final int totalItems) {

            total = firstItem + visibleItemCount;
            Log.e("", "total =" + total);

            if (totalItems > 0 && total > 0 && total == totalItems) {
                if (preLast != total) {
                    if (pageCount < LocalPages) {
                        Handler handler = new Handler();
                        handler.postDelayed(new Runnable() {
                            public void run() {
                                pageCount++;
                                 for (All_Post all_Post : allDesc) {
                    descArray.add(all_Post);
                                }
                                if (adapter != null) {
                                    adapter.notifyDataSetChanged();
                                    listView.setAdapter(adapter);
                                    listView.setSelection(totalItems);
                                }
                            }
                        }, 2500);
                    }
                    preLast = total;
                    Log.e("", "11111111111 preLast=" + preLast);
                }

                preLast = total;
                Log.e("", "222222222222222 preLast=" + preLast);
                if (pageCount == LocalPages)
                {
                    if (preLast == total)
                    {

                            progressBar.setVisibility(View.GONE);
                            btnLoadMore.setVisibility(View.VISIBLE);
                            btnLoadMore.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 60));
                            pageCount = 0;

                       }

                    }
            }
            }
        }
   });}

0 个答案:

没有答案