title: Android quiz random questions
body: <p>How can I randomize the questions that will show with <code>RadioButton</code>. I looked in the other posts but the answer didn't work for me.</p>
  
  <pre><code>import android.app.Activity;
  import android.content.Intent;
  import android.content.pm.ActivityInfo;
  import android.media.MediaPlayer;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.Menu;
  import android.view.View;
  import android.widget.Button;
  import android.widget.RadioButton;
  import android.widget.RadioGroup;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import java.util.List;
  
  public class QuizActivity extends Activity {
      int score = 0;
      int qnum = 1;
      TextView txtQuestion;
      RadioButton rda, rdb, rdc, rdd;
      Button butNext;
      RadioGroup rdgrp;
  
      String corAnswer = "";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
          setContentView(R.layout.activity_quiz);
          DbHelper db = new DbHelper(this);
          rdgrp = (RadioGroup) findViewById(R.id.questionAndAnswers);
          txtQuestion = (TextView) findViewById(R.id.textView1);
          rda = (RadioButton) findViewById(R.id.radio0);
          rdb = (RadioButton) findViewById(R.id.radio1);
          rdc = (RadioButton) findViewById(R.id.radio2);
          rdd = (RadioButton) findViewById(R.id.radio3);
          butNext = (Button) findViewById(R.id.button1);
  
  
          corAnswer = "";
          onCreateQuestion();
      }
  
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.activity_quiz, menu);
          return true;
      }
  
  
      public void onCreateQuestion() {
          String level = getIntent().getExtras().getString("level");
          DbHelper db = new DbHelper(this);
          db.getQuestByLevel(level, qnum);
  
          txtQuestion.setText(db.question);
          rda.setText(db.optionA);
          rdb.setText(db.optionB);
          rdc.setText(db.optionC);
          rdd.setText(db.optionD);
          corAnswer = db.answer;
  
          qnum++;
  
      }
  
      public void onClickNext(View view) {
          String level = getIntent().getExtras().getString("level");
          DbHelper db = new DbHelper(this);
          db.getQuestByLevel(level, qnum);
  
          RadioGroup grp = (RadioGroup) findViewById(R.id.questionAndAnswers);
          RadioButton answer = (RadioButton) findViewById(grp.getCheckedRadioButtonId());
          if (answer == null)
          {
              Toast.makeText(QuizActivity.this, "select an answer please", Toast.LENGTH_SHORT).show();
  
  
              return;
          }
          if (corAnswer!= null &amp;&amp; corAnswer.equalsIgnoreCase((String) answer.getText()))
          {
              score++;
              Log.d("answer", "Your score" + score);
          }
          if (qnum &lt;= 5) {
  
  
          } else {
              Intent intent = new Intent(QuizActivity.this, ResultActivity.class);
              Bundle b = new Bundle();
              b.putInt("score", score);
              intent.putExtras(b);
              startActivity(intent);
              finish();
          }
  
          txtQuestion.setText(db.question);
          rda.setText(db.optionA);
          rdb.setText(db.optionB);
          rdc.setText(db.optionC);
          rdd.setText(db.optionD);
          corAnswer = db.answer;
          qnum++;
          rdgrp.clearCheck();
      }
  
  
  }
  </code></pre>