简体   繁体   中英

My if statement don't work in my application

In my sample code , I have problem. I want check all of if-statements but it just run the last If-statements(it just run the first and the last if).and finally I want to show the a1-a10. but it doesn't work.

here: I compare my Question id (qid) with the first question in my unit.and check the item that user select.then I show the question and I add my question id(qid).

    if (qid == unitid) {
        if (rda.isChecked()) {
            a1 = rda.getText().toString();
        }
        if (rdb.isChecked()) {
            a1 = rdb.getText().toString();
        }
        if (rdc.isChecked()) {
            a1 = rdc.getText().toString();
        }
        if (rdd.isChecked()) {
            a1 = rdd.getText().toString();
        }
    }
    currentQ = quesList.get(qid);

    setQuestionView();

qid++;

then: I do this process again for the next question.

if (qid < unitid + 10) {
{


grp.clearCheck();
currentQ = quesList.get(qid);
setQuestionView();

if (qid == unitid + 1) {
    qid++;
    if (rda.isChecked()) {
        a2 = rda.getText().toString();
    }
    if (rdb.isChecked()) {
        a2 = rdb.getText().toString();
    }
    if (rdc.isChecked()) {
        a2 = rdc.getText().toString();
    }
    if (rdd.isChecked()) {
        a2 = rdd.getText().toString();
    }
}


currentQ = quesList.get(qid);
setQuestionView();
if (qid == unitid + 2) {
    qid++;
    if (rda.isChecked()) {
        a3 = rda.getText().toString();
    }
    if (rdb.isChecked()) {
        a3 = rdb.getText().toString();
    }
    if (rdc.isChecked()) {
        a3 = rdc.getText().toString();
    }
    if (rdd.isChecked()) {
        a3 = rdd.getText().toString();
    }
}


currentQ = quesList.get(qid);
setQuestionView();
if (qid == unitid + 3) {
    if (rda.isChecked()) {
        a4 = rda.getText().toString();
    }
    if (rdb.isChecked()) {
        a4 = rdb.getText().toString();
    }
    if (rdc.isChecked()) {
        a4 = rdc.getText().toString();
    }
    if (rdd.isChecked()) {
        a4 = rdd.getText().toString();
    }
}


currentQ = quesList.get(qid);
setQuestionView();
if (qid == unitid + 4) {
    if (rda.isChecked()) {
        a5 = rda.getText().toString();
    }
    if (rdb.isChecked()) {
        a5 = rdb.getText().toString();
    }
    if (rdc.isChecked()) {
        a5 = rdc.getText().toString();
    }
    if (rdd.isChecked()) {
        a5 = rdd.getText().toString();
    }
}


currentQ = quesList.get(qid);
setQuestionView();
if (qid == unitid + 5) {
    if (rda.isChecked()) {
        a6 = rda.getText().toString();
    }
    if (rdb.isChecked()) {
        a6 = rdb.getText().toString();
    }
    if (rdc.isChecked()) {
        a6 = rdc.getText().toString();
    }
    if (rdd.isChecked()) {
        a6 = rdd.getText().toString();
    }
}


currentQ = quesList.get(qid);
setQuestionView();
if (qid == unitid + 6) {
    if (rda.isChecked()) {
        a7 = rda.getText().toString();
    }
    if (rdb.isChecked()) {
        a7 = rdb.getText().toString();
    }
    if (rdc.isChecked()) {
        a7 = rdc.getText().toString();
    }
    if (rdd.isChecked()) {
        a7 = rdd.getText().toString();
    }
}


currentQ = quesList.get(qid);
setQuestionView();
if (qid == unitid + 7) {
    if (rda.isChecked()) {
        a8 = rda.getText().toString();
    }
    if (rdb.isChecked()) {
        a8 = rdb.getText().toString();
    }
    if (rdc.isChecked()) {
        a8 = rdc.getText().toString();
    }
    if (rdd.isChecked()) {
        a8 = rdd.getText().toString();
    }
}


currentQ = quesList.get(qid);
setQuestionView();
if (qid == unitid + 8) {
    if (rda.isChecked()) {
        a9 = rda.getText().toString();
    }
    if (rdb.isChecked()) {
        a9 = rdb.getText().toString();
    }
    if (rdc.isChecked()) {
        a9 = rdc.getText().toString();
    }
    if (rdd.isChecked()) {
        a9 = rdd.getText().toString();
    }
}


currentQ = quesList.get(qid);
setQuestionView();
if (qid == unitid + 9) {
    if (rda.isChecked()) {
        a10 = rda.getText().toString();
    }
    if (rdb.isChecked()) {
        a10 = rdb.getText().toString();
    }
    if (rdc.isChecked()) {
        a10 = rdc.getText().toString();
    }
    if (rdd.isChecked()) {
        a10 = rdd.getText().toString();
    }
}

but It just show the first and the last if. It doesn't run the other if-statement.

if it is String, you should compare like this:

if(qid.eqlualsIgnoreCase(unitId)){
//code
}

As you are saying that it is String then your logic is incorrect qid should be an integer type.

if (qid < unitid + 10) {
 for(int i=0; i<10; i++)
 grp.clearCheck();
 currentQ = quesList.get(qid);
 setQuestionView();

 if (qid == unitid + ++i) //if qid is 1 or if qid initialized to 0 put i instead of ++i  
 {
    qid++;
    if (rda.isChecked()) {
        a[i] = rda.getText().toString();
    }
    if (rdb.isChecked()) {
        a[i] = rdb.getText().toString();
    }
    if (rdc.isChecked()) {
        a[i] = rdc.getText().toString();
    }
    if (rdd.isChecked()) {
        a[i] = rdd.getText().toString();
    }
}
currentQ = quesList.get(qid);

setQuestionView();

This just an example you may do but you need to create array and have to modify many other things. And what you are using in your if should be an integer type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM