Reputation: 278
I have a RecyclerView which contains TextViews as items. When I click on a item, it selects him and it normally changes layout of the TextView.
However, TextView's layout doesn't update except if I scroll the RecyclerView. In back the item is selected, but in front, I have to scroll the RecyclerView to see the change.
For information, my RecyclerView is in a Fragment which is in a ViewPager2.
I use notifyItemChanged()
and I tried with notifyDataSetChanged()
. I've also tried with requestLayout()
and invalidate()
on the RecyclerView and Parent's layout.
EDIT 2 :
I've found the source of my problems, see this post to check out.
Upvotes: 1
Views: 258
Reputation: 11
Sorry about my poor English ! Is it works on Android5.1 or Android6.0,I have the same problem .finally I find a solution
1. add a ListView(you can set the height or width to zero make it invisiable) to the Fragment where RecyleView in
2. set a Adapter to ListView
then the RecyclerView in this fragment can notifyDataSetChanged() correctly ,even the RecyclerView in other fragment of the same ViewPager2 can work correctly, I don't know how it works ,but it works for me ,hope it works for you too
Upvotes: 1