英文:
How to update/refresh data of selected item from RecyclerView
问题
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:
https://stackoverflow.com/q/9572795/21193451
https://stackoverflow.com/q/4042434/21193451
https://stackoverflow.com/q/32457406/21193451
英文:
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:
https://stackoverflow.com/q/9572795/21193451
答案1
得分: 1
你可以使用:
-
For循环
for(MyClass item: currentList){ if(item.getId() == yourItem.getId()){ return item; } return null; //未找到项目。 }
-
或者如果你有RecyclerView中项目的位置,你可以使用:
currentList.get(position)
英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论