我正在创建一个测验应用程序,我想使用一个递归函数遍历问题,选择和答案字符串数组。如果选择了具有正确答案的按钮,则应使用递归以不同的值再次调用该方法,但这不会发生。我希望我的代码不会太凌乱,因为我是一个初学者。
这是我的代码:
public class Info extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_info);
String [] questionsIT = {
"When did Windows 10 appear?",
"When did the first iPhone appear?",
"Who presented the iPhone 4?",
"What's the most widely used browser in the world?",
"Which language is Windows written in?",
"WHich country did the inventor of PHP language come from?",
"How many cores does a quad-core processor have?",
"Which company owns XBOX?",
"Which company owns PlayStation?",
"In which american state are the Google headquarters located?"
};
String [][] choicesIT = {
{"1989", "2015", "2002", "2012"},
{"1999", "2006", "2008", "2007"},
{"Steve Jobs", "Tim Cook", "Bill Gates", "Steve Wozniak"},
{"Microsoft Edge", "Internet Explorer", "Google Chrome", "Mozilla Firefox"},
{"C++", "Pascal", "Java", "Perl"},
{"Romania", "UK", "Greenland", "Germany"},
{"2 cores", "4 cores", "6 cores", "8 cores"},
{"Google", "Sony", "Samsung", "Microsoft"},
{"Microsoft", "Sony", "Apple", "Nokia"},
{"New York", "Texas", "Ohio", "California"}
};
String [] answersIT = {
"2015",
"2007",
"Steve Jobs",
"Google Chrome",
"C++",
"Greenland",
"4 cores",
"Microsoft",
"Sony",
"California"
};
int[] picsID = {R.drawable.win10, R.drawable.iphone1, R.drawable.apple};
RelativeLayout rlinfo = findViewById(R.id.rlinfo);
final TextView intrbinfo = findViewById(R.id.intrbinfo);
int score = 0;
int i = 0;
intrbinfo.setText("");
Something(questionsIT, choicesIT, answersIT, i, score,intrbinfo);
}
public int Something(String[] q, String [][]ch, String[] a, int x, int scor, TextView textView)
{
x = 0;
scor = 0;
int y = 0;
RadioGroup radioGroup = findViewById(R.id.RadioGroup);
RadioButton[] chooses = {findViewById(R.id.choose1), findViewById(R.id.choose2), findViewById(R.id.choose3), findViewById(R.id.choose4)};
textView.setText(q[x]);
chooses[0].setText(ch[x][0]);
chooses[1].setText(ch[x][1]);
chooses[2].setText(ch[x][2]);
chooses[3].setText(ch[x][3]);
if (chooses[0].isChecked() && chooses[0].equals(a[x]))
{
scor++; x++;
Something(q,ch,a, x,scor, textView);}
if(y == 10){
return 0; //Here the loop stops cause there are no more questions
}
if (chooses[1].isChecked() && chooses[1].equals(a[x]))
{
scor++; x++;
Something(q,ch,a, x,scor, textView);}
if(y == 10){
return 0;
}
if (chooses[2].isChecked() && chooses[2].equals(a[x]))
{
scor++; x++;
Something(q,ch,a, x,scor, textView);}
if(y == 10){
return 0;
}
if (chooses[3].isChecked() && chooses[3].equals(a[x]))
{
scor++; x++;
Something(q,ch,a, x,scor, textView);}
if(y == 10){
return 0;
}
return y;
}
}