lundi 2 novembre 2015

How do i limit the result of a sqlite loop in a for loop?

I have 4 radio buttons nested in 4 radio groups. The answers_log string is the result of a sqlite query. The query returns from the database 4 results. I want to display only this 4 results in each radio group. With this code, in stead of displaying 4 radio buttons in each radio group, are displayed 16 results. How can i fix this problem? Here is my code:

    answer = new RadioButton[4];
    radioGroup = new RadioGroup[4];
    for (int i = 0; i < 4; i++) {
        radioGroup[i] = new RadioGroup(this);
        radioGroup[i].setOrientation(RadioGroup.VERTICAL);
        for (Answer an : answers) {
            String answers_log = an.getAnswer();
            for (int j = 0; j < 4; j++) {
                answer[j] = new RadioButton(this);
                answer[j].setText(answers_log);
                answer[j].setId(j);
                radioGroup[i].addView(answer[j]);
            }
        }
        linearLayout.addView(radioGroup[i]);

Thanks!

Aucun commentaire:

Enregistrer un commentaire