title: ViewPager's PageAdapter get reset on orientation change
body: <p>I'm using a <code>ViewPager</code> for a multiple-choice exam app, which chooses out randomly thirty questions out of a bigger set. I do this in the <code>PageAdapter</code> that is supplying the pages to the <code>ViewPager</code>.</p>
  
  <p>The problem is that when an orientation change occurs, not only the pager but also the adapter gets reloaded - I know how to save the current pager position but when the adapter gets reset, it also chooses new questions from the set. What would be the proper way to handle this?</p>
  
  <p>Also, side question - what would be the best way to register the choices on the RadioGroups? Directly by click or in a different way?</p>
  
  <p>I'm fairly new to the Android app developement.</p>
  
  <hr>
  
  <p>Activity:</p>
  
  <pre><code>public class MyActivity extends SherlockActivity {
      ActionBar actionBar;
      ViewPager pager;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          pager = new ViewPager(this);
          setContentView(pager);
          QuestionsAdapter adapter = new QuestionsAdapter(this);
          pager.setAdapter(adapter);
  
          int position = 0;
          if (savedInstanceState != null) {
              position = savedInstanceState.getInt("Q_NUMBER");
          }         
          pager.setCurrentItem(position);
      }
  
      @Override
      public void onSaveInstanceState(Bundle savedInstanceState) {
          int position = pager.getCurrentItem();
          savedInstanceState.putInt("Q_NUMBER", position);
      }
  }
  </code></pre>
  
  <p>Adapter:</p>
  
  <pre><code>class QuestionsAdapter extends PagerAdapter {
      Context context;
      QuestionsHelper dbQuestions;
      boolean exam;
      List&lt;HashMap&lt;String,Object&gt;&gt; examQuestions;
  
      public QuestionsAdapter(Context context, boolean exam) {
          this.context = context;
          this.examQuestions = GetQuestionsFromDB(30);
      }
  
      public Object instantiateItem(View collection, int position) {
          LayoutInflater inflater = (LayoutInflater) collection.getContext()
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View view;
          HashMap&lt;String,Object&gt; q;
  
          view = inflater.inflate(R.layout.exam_question_layout, null);
          q = getQuestion(position+1);
  
          ((TextView)view.findViewById(R.id.q_number)).setText(Integer.toString(position+1)+".");
          ((TextView)view.findViewById(R.id.q_question)).setText(q.get("question").toString());
          ((RadioButton)view.findViewById(R.id.q_answer_a)).setText(q.get("answer_a").toString());
          ((RadioButton)view.findViewById(R.id.q_answer_b)).setText(q.get("answer_b").toString());
          ((RadioButton)view.findViewById(R.id.q_answer_c)).setText(q.get("answer_c").toString());
  
          ((ViewPager)collection).addView(view, 0);
          return view;
      }
  }
  </code></pre>