我正在开发一个测试应用程序。我现在对其进行了编码,它对第一个问题很有用。但我不知道如何回答第二个问题。我尝试使用 while-do 循环和其他方法来做到这一点,但没有奏效。我能做些什么?任何人都可以帮助我吗?
public class testing extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testing);
TextView view = (TextView) findViewById(R.id.soru1);
final Button answer1 = (Button) findViewById(R.id.answer1);
final Button answer2 = (Button) findViewById(R.id.answer2);
final Button answer3 = (Button) findViewById(R.id.answer3);
final Button answer4 = (Button) findViewById(R.id.answer4);
final ArrayList<String> questions= new ArrayList<String>();
countries.add("question1");
countries.add("question2");
countries.add("question3");
countries.add("question4");
countries.add("question5");
countries.add("question6");
countries.add("question7");
countries.add("question8");
final int[] answers= new int[]{
R.drawable.pic1,
R.drawable.pic2,
R.drawable.pic3,
R.drawable.pic4,
R.drawable.pic5,
R.drawable.pic6,
R.drawable.pic7,
R.drawable.pic8,
R.drawable.correct,
R.drawable.wrong,
};
Random soru = new Random();
final int[] rastgele = new int[1];
for (int i=0; i<1; i++)
{rastgele[i]= soru.nextInt(8);}
ArrayList<Integer> cevap = new ArrayList<Integer>();
for (int k = 0; k <= 7; ++k)
{cevap.add(k);}
Collections.shuffle(cevap);
final Integer[] rastgele2 = new Integer[4];
if (rastgele[0]!=cevap.get(0))
{rastgele2[0]=cevap.get(0);}
else
{rastgele2[0]=cevap.get(3);}
if (rastgele[0]!=cevap.get(1))
{rastgele2[1]=cevap.get(1);}
else
{rastgele2[1]=cevap.get(3);}
if (rastgele[0]!=cevap.get(2))
{rastgele2[2]=cevap.get(2);}
else
{rastgele2[2]=cevap.get(3);}
rastgele2[3]=rastgele[0];
Collections.shuffle(Arrays.asList(rastgele2));
view.setText(questions.get(rastgele[0]));
answer1.setBackgroundResource(answers[rastgele2[0]]);
answer1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (rastgele[0]==rastgele2[0])
{answer1.setBackgroundResource(answers[8]);
questions.remove(rastgele[0]);}
else {answer1.setBackgroundResource(answers[9]);}
}
});
answer2.setBackgroundResource(answers[rastgele2[1]]);
answer2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (rastgele2[1]==rastgele[0])
{answer2.setBackgroundResource(answers[8]);
countries.remove(rastgele[0]);}
else {answer2.setBackgroundResource(answers[9]);}
}
});
answer3.setBackgroundResource(answer[rastgele2[2]]);
answer3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (rastgele2[2]==rastgele[0])
{answer3.setBackgroundResource(answer[8]);
countries.remove(rastgele[0]);}
else {answer3.setBackgroundResource(answer[9]);}
}
});
answer4.setBackgroundResource(answer[rastgele2[3]]);
answer4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (rastgele2[3]==rastgele[0])
{answer4.setBackgroundResource(answer[8]);
countries.remove(rastgele[0]);}
else {answer4.setBackgroundResource(answer[9]);}
}
});}
}