mardi 22 mars 2016

how to update Listview while at the end of Listview scrolling in Android?

I'm trying to display the listview from sqlite. At the end of Listview I want to load next 10 data from sqlite and this process will continue till data ends in SQLite. But the issue is data load at first time successfully and when i scroll 3rd time page/data does not load and after LocalListPageIndex= 2 then progress bar is continuously running.

Here is my Code of 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 <= 5) {
                    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()
                            {
                                LocalListPageIndex += 1;

                                int OFFSET_SCROLL = 10
                                List<All_Post> allDesc = dbhelper.getAllDescriptions(OFFSET_SCROLL);
                                for (All_Post all_Post : allDesc) {
                                    descArray.add(all_Post);
                                }
                                if (adapter != null) {
                                    adapter.notifyDataSetChanged();
                                   // adapter = new AllPostAdapter(getApplicationContext(), R.layout.allpostlist, descArray);
                                    listView.setAdapter(adapter);
                                    //listView.invalidateViews();
                                    listView.setSelection(totalItemCount);

                                }
                            }
                        }, 15000);
                    }

                }   if (LocalListPageIndex == 5)  {
                    Log.e("hide footer", "footer hide");
                    listView.removeFooterView(progressBar);
                }
            }
            X = firstVisibleItem;

        }
    });

Aucun commentaire:

Enregistrer un commentaire