I'm using a ViewPager
with a FragmentPagerStateAdapter
. Every page has a list, manually managed => I create views for this rows by inflating a layout from xml. Resulting in, that views in different rows have the same id. Because the rows are inflated from XML...
The behaviour now is following:
Page 1 looks like following:
// Page 1:
// Row 1: EditText = "Test1"
// Row 2: EditText = "Test2"
I swipe to Page 2 and then to Page 3, afterwards I swipe back to Page 1 and Page 1 looks like following:
// Page 1:
// Row 1: EditText = "Test2"
// Row 2: EditText = "Test2"
Problem: All EditTexts display the value of the lastEditText in the list... (Note, the EditTexts have the same ID).
If I manually set the ids of my EditTexts to the row index, everything works fine.
Is this normal? Is there an easy (good) solution for that problem?
Tt seems like a bug in Android 3.X
The solution is setting ID's manually so they never match between fragments or resetting id's when Fragment becomes invisible. I like the second one since it can be easily disabled or enabled and requires no special id handling.
The Fragment
setUserVisibleHint is triggered by ViewPager when the Fragment becomes visible. The ViewIdResetter makes sure only one Fragment at a time has the same id's set.