Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have RecyclerView.Adapter<RecyclerView.ViewHolder> with pagination button(Load More)

Load More button in RecyclerView like Footer. Each request get 20 rows and if I get <20 items I need disable this button:

 @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ViewHolder) {
        } else if (holder instanceof FooterViewHolder) {
            viewHolder.loadMore.setEnabled(isVisibleLoadButton);
public void addData(List<TransactionItem> opcTransactions) {
        final int positionStart = transactionItems.size()+1;
        isVisibleLoadButton = opcTransactions.size() >= 20;
        transactionItems.addAll(opcTransactions);
        notifyItemRangeInserted(positionStart, opcTransactions.size());

If I get opcTransactions with 1 or more items isVisibleLoadButton set false and my load More button set disable. But If I get emty list opcTransactions size = 0 - load More button not diasbled.

@Override
    public int getItemCount() {
        if (transactionItems == null) {
            return 0;
        if (transactionItems.size() == 0) {
            //Return 1 here to show nothing
            return 1;
        // Add extra view to show the footer view
        return transactionItems.size() + 1;

positionStart should point to last item of your list . and indexing starts form ZERO. Use it as .

final int positionStart = transactionItems.size();
                not. I use this specially. if I add +1 - when I load first 20 items my list not scroled to buttom (stackoverflow.com/a/30455749/4781349) and if I not use +1 button not disabled too
– ip696
                Dec 22, 2017 at 9:48
                Whats the point of +1? when you are ultimately calling notifyItemRangeInserted not notifyItemChanged .
– ADM
                Dec 22, 2017 at 9:52
                I do not understand you. I wrote a link with the answer why I use +1. and clarified that even if I do not use +1, it still does not work
– ip696
                Dec 22, 2017 at 9:58
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.