0

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 Answers1

1

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)

  • recyclerview items and consequently their positions may change each time since some new items. So I think I cannot use 'currentList'! – user21193451 Jun 13 '23 at 16:05