mardi 22 mars 2016

SQlite Pagination on ListView scrolling in Android

I need help to creating pagination with Sq-lite local database at the end of List-view Scrolling.I'm trying to increase the local page index 5 times on List view Scrolling at the end and append the next 10 Sq-lite data rows in List-view , but something is wrong with my code.Only 1 page size creating when I scrolling 2nd time page size does not increase by 1 and progress-bar is running contentiously . Can some one help me to solve this .

Here is my Code for ListView Scrolling.

listView.removeFooterView(progressBar);
        listView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
            }

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

                lastInScreen = firstVisibleItem + visibleItemCount;

                if (X != firstVisibleItem)
                {
                   if (LocalListPageIndex < LocalPages )
                   {
                       //Toast.makeText(getApplicationContext(), "Your Last Item." + lastInScreen, Toast.LENGTH_SHORT).show();

                        if (lastInScreen == totalItemCount)
                        {
                            listView.addFooterView(progressBar);
                        // Execute some code after 15 seconds have passed
                            Handler handler = new Handler();
                            handler.postDelayed(new Runnable()
                            {
                                public void run()
                                {
                                    //  populateList(OFFSET_SCROLL);
                                   Pagination_Demo.this.runOnUiThread(new Runnable() {
                                        @Override
                                        public void run()
                                        {
                                            LocalListPageIndex +=1;

                                            int OFFSET_SCROLL = LocalListPageIndex * 10;
                                            Log.e("", "LocalListPageIndex = " + LocalListPageIndex + " Load More !!!" + " & OFFSET value is = " + OFFSET_SCROLL);

                                            sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                                            final SharedPreferences.Editor editor = sharedPreferences.edit();
                                            editor.putInt("item_position", totalItemCount);
                                            editor.commit();
                                           // populateList(OFFSET_SCROLL);

                                            List<All_Post> allDesc = dbhelper.getAllDescriptions(OFFSET);
                                            for (All_Post all_Post : allDesc)
                                            {
                                                descArray.add(all_Post);
                                            }

                                            if (adapter != null) {
                                                adapter.notifyDataSetChanged();
                                               // adapter = new AllPostAdapter(this, R.layout.allpostlist, descArray);
                                                listView.setAdapter(adapter);
                                                listView.setSelection(totalItemCount);
                                            }
                                        }
                                    });
                                }
                            }, 4000);
                        }
                   }

                    else
                    {
                        Log.e(" Stop ", " Loading !!!!!! ");
                        Log.e("hide footer", "footer hide");
                        listView.removeFooterView(progressBar);
                    }
                }
                X = firstVisibleItem;

            }
        });

Thanks in advanced .

Aucun commentaire:

Enregistrer un commentaire