1

This is how I am setting up recyclerview.

mRecyclerViewRides = (RecyclerView) findViewById(R.id.recyclerViewRides);
    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    mRecyclerViewRides.setHasFixedSize(true);
    // use a linear layout manager
    mLinearLayoutManager = new LinearLayoutManager(getApplicationContext());
    mRecyclerViewRides.setLayoutManager(mLinearLayoutManager);
    mRideListAdapter = new FindRideListAdapter(getApplicationContext(), mRecyclerViewRides, mRideDetailArrayList, mImageOptions, mImageLoader, this);
mRecyclerViewRides.setAdapter(mRideListAdapter);
mRecyclerViewRides.addOnScrollListener(new EndlessRecyclerOnScrollListener(mLinearLayoutManager) {
        @Override
        public void onLoadMore(int current_page) {
            Log.e(TAG,"Scroll Count ==> "+(++mIntScrollCount));
            if(!flagFirstLoad) {
                mOffset = mOffset + mLimit;
                getRideList(mOffset, mLimit);
            }
        }
    });

This is the code for endless recycler view scroll listner.

public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener {
public static String TAG = EndlessRecyclerOnScrollListener.class.getSimpleName();

private int previousTotal = 0; // The total number of items in the dataset after the last load
private boolean loading = true; // True if we are still waiting for the last set of data to load.
private int visibleThreshold = 1; // The minimum amount of items to have below your current scroll position before loading more.
int firstVisibleItem, visibleItemCount, totalItemCount;

private int current_page = 1;

private LinearLayoutManager mLinearLayoutManager;

public EndlessRecyclerOnScrollListener(LinearLayoutManager linearLayoutManager) {
    this.mLinearLayoutManager = linearLayoutManager;
}

/**
 * function to reset values of the properties of this class to initial
 */
public void resetValues(){
    previousTotal = 0;
    loading = true;
    visibleThreshold = 1;
    firstVisibleItem = 0;
    visibleItemCount = 0;
    totalItemCount = 0;
}

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    visibleItemCount = recyclerView.getChildCount();
    totalItemCount = mLinearLayoutManager.getItemCount();
    firstVisibleItem = mLinearLayoutManager.findFirstVisibleItemPosition();

    if (loading) {
        if (totalItemCount > previousTotal) {
            loading = false;
            previousTotal = totalItemCount;
        }
    }
    if (!loading && (totalItemCount - visibleItemCount)
            <= (firstVisibleItem + visibleThreshold)) {
        // End has been reached

        // Do something
        current_page++;

        onLoadMore(current_page);

        loading = true;
    }
}

public abstract void onLoadMore(int current_page);}

So now whenever i scroll to bottom of the list onLoadMore() gets called twice and even intialy when i call getRideList() for the first time onScroll is getting invoked. I don't understand why?

Pritam Kadam
  • 2,783
  • 3
  • 16
  • 32

1 Answers1

-1

Updated my support library and its working fine now.

Pritam Kadam
  • 2,783
  • 3
  • 16
  • 32