ListView中的SQlite分页在Android中滚动

时间:2016-03-23 06:14:44

标签: android sqlite listview pagination

我坚持在Android中实现分页。我需要帮助在List-view滚动结束时使用Sq-lite本地数据库创建分页。我试图在每页添加10个项目并增加本地页面索引列表视图中最多5次在末尾滚动并在列表视图中追加下一个10 Sq-lite数据行,但我的代码出现问题。当我滚动第二次页面大小时,仅创建1页大小不会增加1和进度条有争议地运行。有人可以帮我解决这个问题。

这是我的ListView滚动代码。

listView.addFooterView(footer);
        // Implementing scroll refresh
        listView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int i) {
            }

            @Override
            public void onScroll(AbsListView absListView, int firstItem, int visibleItemCount, final int totalItems) {
                //Log.e("Get position", "--firstItem:" + firstItem + "  visibleItemCount:" + visibleItemCount + "  totalItems:" + totalItems + "  pageCount:" + pageCount);
                int total = firstItem + visibleItemCount;

               Log.e("", "onScroll LocalPages=" + LocalPages);
                // Total array list i have so it
                if (pageCount < LocalPages) {

                    if (total == totalItems) {

                        // Execute some code after 8 seconds have passed
                        Handler handler = new Handler();
                        handler.postDelayed(new Runnable()
                        {
                            public void run()
                            {
                                listView.addFooterView(footer);
                                OFFSET = pageCount * 10 ;
                                //Log.e("","After OFFSET pageCount =" + pageCount + "  OFFSET value ="+OFFSET);
                                List<All_Post> allDesc = dbhelper.getAllDescriptions(OFFSET);
                                for (All_Post all_Post : allDesc)
                                {
                                    descArray.add(all_Post);
                                }
                                if(adapter != null)
                                {
                                    adapter.notifyDataSetChanged();
                                    listView.setAdapter(adapter);
                                    listView.setSelection(totalItems);

                                    pageCount += 1;
                                    Log.e("","  pageCount =" + pageCount + " LocalPages="+LocalPages);

                                }
                            }
                        }, 8000);
                    }
                } else {
                    Log.e("hide footer", "footer hide");
                    listView.removeFooterView(footer);
                }
            }
        });

先谢谢。

0 个答案:

没有答案