5

I am passing pagedlist values to adapter using submit list. when i update a single item consider i am clicking a like button of a feed in a recyclerview. how to update the single item.

i am following this example for paging implementation

https://github.com/saquib3705/PagingLibrarySampleApp

which just loads data and update the recyclerview. I would like to add like button for the items and update the list when user liked how to achieve it. Also look at this which is what i m exactly looking for Update list items in PagingLibrary w/o using Room (Network only)

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Vignesh R
  • 125
  • 8
  • DiffUtill class will give you that functionality. Follow this guide https://medium.com/@sharmadhiraj.np/android-paging-library-step-by-step-implementation-guide-75417753d9b9 – Hussnain Haidar Mar 08 '19 at 09:55

1 Answers1

-3

Assuming my guess is correct:

  1. Your view model has LiveData<PagedList<Article>> getter
  2. You have PagedListAdapter implementation and set data into it via submitList
  3. You share your view model between list and list item (which is natural)

Then by adding this into your adapter constructor (naturally Article is just sample class representing some entity, you will have your own) :

        super(new DiffUtil.ItemCallback<Article>() {
            @Override
            public boolean areItemsTheSame(@NonNull Article article1, @NonNull Article article2) {
                return article1.getId().equals(article2.getId());
            }

            @Override
            public boolean areContentsTheSame(@NonNull Article article1, @NonNull Article article2) {
                return article1.equals(article2);
            }
        });

...you have your question solved automatically.

ror
  • 3,295
  • 1
  • 19
  • 27