I have a master-detail fragment layout, that looks like this:
When a number from the list view is selected values in detail view change(i.e. radio button text changes). I have the following problem: when I click number 1 in list view and choose option 1 in detail view, and then click different number in list view the detail view option is already set. If at that point I choose different option and go back to list view 1 then the last option is set (i.e. my previous choice is not persistent).
How can I make sure that my choices of radio buttons persist across list view options, and that previous radio button choices do not affect next radio button choices?
My current approach is to have static array in activity that records option choice for each list view number. When I return to specific list view number I look up the radio button chosen from the array and set detail view accordingly. But previous radio button choice is still set in the next radio button group.
If you are using the same detail fragment for all items in list view, I think you should save the current user's choice into listview item's Tag object on every selection change.
Save it just before the change (setTag()), and load user's choice for the item if getTag() for it is not null.
Alternatively, you can use different fragments of the same (or different) type inside a ViewPager and use your ListView to switch between pages. This may be a little overhead in your case, but you get state saving, backtrace and many more for free. Also you'll get cleaner code. I would prefer this solution.