How to update/refresh data of selected item from RecyclerView

31 Views Asked by At

I have a recyclerview that its data come from viewModel and database using retrofit. I know how to update all data of recyclerview every time that I want. but when I go to the selected item page using navigation component with selected item data as its argument, I don't know how to update data of this page (using e.g. swiperefresh).

I can update all data, that its output is a List, but I don't know how to find the selected item among the list. It is easy in Array case using index but here it is a List. Any simple solution?

here are some related posts but I couldn't use them:

Convert list to array in Java

Converting 'ArrayList<String> to 'String[]' in Java

How to update/refresh specific item in RecyclerView

1

There are 1 best solutions below

1
DevKazonovic On

You can use:

  • For loop

    for(MyClass item: currentList){
      if(item.getId() == yourItem.getId(){
        return item;
      } 
      return null; //Item Not found.
    }
    
  • Or if you have the item position in the recyclerview you can use : currentList.get(position)