3

I am using endless Recyclerview which is loading data from Parse.com database.The problem I am facing is that it is displaying two loading images like shown in below screen.I want to display one item at time and then on scrolling show the icon then load the next item.

Code for EndlessScroll is -

public abstract class EndlessScroll extends RecyclerView.OnScrollListener {
    public static String TAG = EndlessScroll.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 = 2; // The minimum amount of items to have below your current scroll position before loading more.
    int firstVisibleItem, visibleItemCount, totalItemCount;

    Context context;    
    private int current_page = 1;    
    private LinearLayoutManager mLinearLayoutManager;

    public EndlessScroll(LinearLayoutManager linearLayoutManager, Context context) {
        this.mLinearLayoutManager = linearLayoutManager;
        this.context = context;
    }

    @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);
}

enter image description here

I have started working in android of late.

I am not sure why the loading behaviour is problematic.

Your help/suggestion/any pointer is much appreciated.

Navoneel Talukdar
  • 3,581
  • 3
  • 17
  • 39
  • This may help you. Ref this link: [link](http://stackoverflow.com/questions/35253695/recyclerview-load-more-with-progressbar-error/35254285#35254285) – Sabari May 04 '16 at 12:07
  • Thanks @Sabari ,it seems expected behaviour from this answer of Vilen http://stackoverflow.com/questions/30681905/adding-items-to-endless-scroll-recyclerview-with-progressbar-at-bottom However if any additional thought pls let me know. – Navoneel Talukdar May 04 '16 at 13:56

0 Answers0