0

I created my DiffUtil like this:

class DiffUtilCall extends DiffUtil.ItemCallback<Cars> {
    @Override
    public boolean areItemsTheSame(@NonNull Cars oldItem, @NonNull Cars newItem) {
        return oldItem.getTitle().equals(newItem.getTitle());
    }

    @Override
    public boolean areContentsTheSame(@NonNull Cars oldItem, @NonNull Cars newItem) {
        return true;
    }

I want to keep refernce to my oldList, so I could "restart" my updated list.

I tried to do this:

private List<Cars> orList;

And than initiaze in the constructor:

public CarsRecyclerViewAdapter() {
    super(new DiffUtilCall());
    orList = getCurrentList()
}

But I just getting an empty list.

How can I solve this?

Noam
  • 485
  • 1
  • 7
  • 18
  • Hi, i'm sorry, but what do you mean exactly by "restart" the list ? – djleop May 21 '20 at 15:52
  • If for example I filter my list with ```Filterable```, I need to restore the list if there is no chars in the search widget – Noam May 21 '20 at 15:53
  • Then it's not by keeping the old list that you achieve that, just requery your datasource with an empty filter, it is more reliable and easy to handle. – djleop May 21 '20 at 16:24
  • @djleop I don't sure I understood what you meant, can you give me an example or reference article please? I pass my data through LiveData observer like this - ```adapter.submitList(carsList)``` – Noam May 21 '20 at 16:27
  • I don't have any example right now... But it's good if you use live data, your filter should apply to the list inside the live data. If you use Viewmodels, you should bind the filter actions to viewmodel methods, then the viewmodel filters the list, wich is observed. – djleop May 22 '20 at 07:06

0 Answers0