Рекурсивный метод не работает в Android - PullRequest
0 голосов
/ 18 октября 2018

Я создаю приложение для викторины и хочу использовать рекурсивную функцию для циклического перебора строковых массивов вопросов, вариантов выбора и ответов.Если выбрана кнопка с правильным ответом, метод должен быть вызван снова с другими значениями с использованием рекурсии, но этого не происходит.Я надеюсь, что мой код не слишком грязный, так как я новичок.

Вот мой код:

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;
}
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...