0

I have a recycler view in which I load data from url which works fine. The problem starts when I want to load more data (when scrolling ends) and to show a progress bar at the bottom and load more data. How can I do that? please tell me.

Here is my code where I want to load more data from Url below previous data .

mUserAdapter.setOnLoadMoreListener(new OnLoadMoreListener() {
        @Override
        public void onLoadMore() {
            Log.e("haint", "Load More");
            mUsers.add(null);
            mUserAdapter.notifyItemInserted(mUsers.size() - 1);
            m_Handler.post(new Runnable() {
                @Override
                public void run() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        Log.e("haint", "Load More 2");
                        sz_RecordCount = String.valueOf(m_n_DefaultRecordCount);// convert int value to string
                        sz_LastCount = String.valueOf(m_n_DeafalutLastCount);// convert int value to string /////
                        new DealNext().execute(m_DealListingURL);// POST DATA TO SERVER TO LOAD MORE DATA......

                    }
                },3000);


                }
            });
        }
    });

and also I don't want to post delay, I want when the scroll ends to show a progress bar and load more data from URL.

Tal Avissar
  • 10,088
  • 6
  • 45
  • 70
Nitin
  • 163
  • 2
  • 11

1 Answers1

0

Set progress bar as footer for your Recycler view. You can set footer by following this tutorial

http://takeoffandroid.com/android-customview/header-and-footer-layout-for-recylerview/

Then you can check if recycler view has reached bottom using below code.

    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (mRadioGroup.getCheckedRadioButtonId() == R.id.feed_radiobutton_all) {
                if (dy > 0) //check for scroll down
                {
                    visibleItemCount = mLayoutManager.getChildCount();
                    totalItemCount = mLayoutManager.getItemCount();
                    pastVisiblesItems = mLayoutManager.findFirstVisibleItemPosition();

                        if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
                         //This means bottom reached here you can call to fetch more data and progress bar states can be set here. 

                        }
                    }
                }
            }
        }
    });
Ragesh Ramesh
  • 3,470
  • 2
  • 14
  • 20