I am making a quiz app with string array. I want to random questions so that every time user start quiz he will see a different question from string array like if questions array has 8 question then question appear randomly like some time shows 6th question in first position so for that i m using random function and questions appears randomly as i want but options are setting in their sequence not according to question if question number 8 is coming at 1st position with random function then options position 8 will have to set at that position, but its not working so that i want your help to resolve this.
Here is my Code
int flag[]={0,1,3,5,6,7,8};
Random random;
int numbb;
public static int marks=0,correct=0,wrong=0;
LinearLayout linearLayout;
LayoutInflater mLayoutInflater;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_secon);
final TextView score = (TextView)findViewById(R.id.textView4);
TextView textView=(TextView)findViewById(R.id.DispName);
random=new Random();
final int[] numb = {flag[random.nextInt(flag.length)]};
/*
Intent intent = getIntent();
String name= intent.getStringExtra("myname");
if (name.trim().equals(""))
textView.setText("Hello User");
else
textView.setText("Hello " + name);*/
submitbutton=(Button)findViewById(R.id.button3);
quitbutton=(Button)findViewById(R.id.buttonquit);
tv=(TextView) findViewById(R.id.tvque);
radio_g=(RadioGroup)findViewById(R.id.answersgrp);
rb1=(RadioButton)findViewById(R.id.radioButton);
rb2=(RadioButton)findViewById(R.id.radioButton2);
rb3=(RadioButton)findViewById(R.id.radioButton3);
rb4=(RadioButton)findViewById(R.id.radioButton4);
tv.setText(questions[numb[0]]);
rb1.setText(opt[0]);
rb2.setText(opt[1]);
rb3.setText(opt[2]);
rb4.setText(opt[3]);
submitbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//int color = mBackgroundColor.getColor();
//mLayout.setBackgroundColor(color);
if(radio_g.getCheckedRadioButtonId()==-1)
{
Toast.makeText(getApplicationContext(), "Please select one choice", Toast.LENGTH_SHORT).show();
return;
}
RadioButton uans = (RadioButton) findViewById(radio_g.getCheckedRadioButtonId());
String ansText = uans.getText().toString();
// Toast.makeText(getApplicationContext(), ansText, Toast.LENGTH_SHORT).show();
if(ansText.equals(answers[numb[0]])) {
correct++;
Toast.makeText(getApplicationContext(), "Correct", Toast.LENGTH_SHORT).show();
}
else {
wrong++;
Toast.makeText(getApplicationContext(), "Wrong", Toast.LENGTH_SHORT).show();
}
numb[0]++;
if (score != null)
score.setText(""+correct);
if(numb[0] <questions.length)
{
tv.setText(questions[numb[0]]);
rb1.setText(opt[numb[0] *4]);
rb2.setText(opt[numb[0] *4 +1]);
rb3.setText(opt[numb[0] *4 +2]);
rb4.setText(opt[numb[0] *4 +3]);
}
else
{
marks=correct;
Intent in = new Intent(getApplicationContext(),highscore.class);
startActivity(in);
}
radio_g.clearCheck();
}
});
Aucun commentaire:
Enregistrer un commentaire