2

I'm currently using THIS TECHNIQUE to make my RecyclerView endless; but the problem is I want it exactly in opposite. I want to load data into adapter when user scroll up like a chat messenger.

private int previousTotal = 0;
private boolean loading = true;
private int visibleThreshold = 5;
int firstVisibleItem, visibleItemCount, totalItemCount;

mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

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

        visibleItemCount = mRecyclerView.getChildCount();
        totalItemCount = mLayoutManager.getItemCount();
        firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();

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

            Log.i("Yaeye!", "end called");

            // Add to data set
            chatMessages.add(0, new Message("Hello World!"));

            loading = true;
        }
    }
});

1 Answers1

1

you can use this awesome library: https://github.com/stfalcon-studio/ChatKit

see pagination section here: https://github.com/stfalcon-studio/ChatKit/blob/master/docs/COMPONENT_MESSAGES_LIST.md

Momen Zaqout
  • 1,508
  • 1
  • 16
  • 17