Я начинаю разработку Android-приложений. Код ниже - это приложение для викторины, и я хочу, чтобы он задавал случайные вопросы и не повторял вопрос, я пытался использовать флаг2 для случайного генерации вопросов, но я получал ошибки компиляции, может ли кто-нибудь помочь мне с этим. Я также новичок в Java.Android - случайный массив Loop и не повторяется
TextView tv;
Button btn1;
RadioButton rb1,rb2,rb3;
RadioGroup rg;
String Questions[]={"What is 1+1?","Capital of USA?","What is 2+2","Echo with Laughter","Warg"};
String opt[]={"2","3","4", "New York","Washington DC","Maryland", "5","4","6","Stairway to Heaven","Hotel California","Highway to hell","Jon","Bran","Dario" };
String ans[]={"2","Washington DC","4","Stairway to heaven","Bran"};
int flag=0;
public static int correct;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
tv=(TextView)findViewById(R.id.textView2);
btn1=(Button)findViewById(R.id.button2);
rg=(RadioGroup)findViewById(R.id.radioGroup);
rb1=(RadioButton)findViewById(R.id.radioButton);
rb2=(RadioButton)findViewById(R.id.radioButton2);
rb3=(RadioButton)findViewById(R.id.radioButton3);
tv.setText(Questions[flag]);
rb1.setText(opt[0]);
rb2.setText(opt[1]);
rb3.setText(opt[2]);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RadioButton uans = (RadioButton) findViewById(rg.getCheckedRadioButtonId());
String ansText = uans.getText().toString();
if (ansText.equalsIgnoreCase(ans[flag])) {
correct++;
}
else {
Intent in = new Intent(getApplicationContext(),Token.class);
startActivity(in);
}
flag++;
if (flag < Questions.length) {
tv.setText(Questions[flag]);
rb1.setText(opt[flag * 3]);
rb2.setText(opt[(flag * 3)+1]);
rb3.setText(opt[(flag * 3)+2]);
}
else {
Intent in = new Intent(getApplicationContext(),Token.class);
startActivity(in);
}
}
Это сработало для меня, но я не могу перейти к следующему вопросу, и это дает мне ошибку «Слишком большой объем». – Moushfiq
См. Редактирование, которое я сделал. – Talha