I have a ViewPager that iterates through a series of questions,creates a page for each question and then,
adds a dynamically created radio group for each page in the ViewPager .
Each page represents a multiple choice question with the answers being a recorded as a RadioButton in a RadioGroup being checked .
The problem I'm having is I can't figure out way to clear the each radio group's checked button
ie myRadioGroup.clear() .
After I click the "save" button it recreates each view with the radioGroup button that is checked .
When a button is clicked initially the radio button's value gets recorded in an external array.
When I click 'Save' that array gets persisted to the database and cleared out ready for the next series of questions.
The ViewPager uses fragments and by default only keeps the last two created fragment views accessible .
the result of this is that if I 5 pages in myviewpager ,I can clear out the last two pages but
for pages 1 through 3 ,I can't clear the checked button in that page's radiogroup.
I can change the behavior of the ViewPager by using viewPager.setOffscreenPageLimit(5) .
This effectively creates a cache for the 5 fragment views.
I can then clear the radio buttons on all 5 pages .
For 5 pages ,this is not a problem. For a 100 pages or 1000 pages,it will probably cause resource issues with the app.
Is there a way to programmatically clear out these buttons without caching all the pages and fragment views?