Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

How do I Clear Radio Buttons in all tabs in a ViewPager ?

 
Ranch Hand
Posts: 446
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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?




 
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic