My app has a Fragment attached to an Activity
(which would ask yes or no questions to users.)
I have two RadioButton for each question
(one for 'yes' and one for 'No'.)
Based on user's choice for each question the next question will be loaded. For example,
1. Are you at the accident scene?
[ yes ] [ No ]
Now my problem is, when I change the orientation after the visibility of second question, only the first question appear(with RadioButton checked).
How to solve this? I ended here only after extensive google-ing. Please help.
Without seeing a little more code it's hard to tell what the exact issue is but heres a good way to think of your issue:
When you rotate the device the activity saves its state and then restarts in the new orientation. super.onSaveInstanceState(); and super.onRestoreInstanceState(); take care of saving view states but they donot know about any other variables (like ones keeping track of what question the user was on).
Override onSave and onRestore to save / load your data during this transition.
Reading http://developer.android.com/training/basics/activity-lifecycle/index.html should provide more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With