Android:如何使用按钮点击控制循环(例如:就像谁想成为百万富翁应用程序一样)

时间:2014-06-09 05:50:28

标签: android for-loop foreach

请您正在制作一个针对考试准备而量身定制的测验应用。 我坚持提交问题。 请在这里是我的代码。 我希望我的问题能够改变,因为谁想要成为百万富翁应用程序,它会带来第一组问题,并且在给出答案之后,一起出现一个新问题。 请问我该如何解决呢。

    continued = "Continue";
    databaseHelper = new ExamDbHandler(ExamGround.this);
    db = databaseHelper.getWritableDatabase();
    scores = 0;
    tvAnswer = (TextView) findViewById(R.id.answer);
    tvQuestion = (TextView) findViewById(R.id.question);
    tvexplain = (TextView) findViewById(R.id.explain);
    score = (TextView) findViewById(R.id.score);
    scres = score.getText().toString();
    examTitle = (TextView) findViewById(R.id.examTitle);
    bOption1 = (Button) findViewById(R.id.option1);
    bOption2 = (Button) findViewById(R.id.option2);
    bOption3 = (Button) findViewById(R.id.option3);
    bOption4 = (Button) findViewById(R.id.option4);
    confirm = (Button) findViewById(R.id.confirm);
    proceed = (Button) findViewById(R.id.proceedto);
    ahint = (LinearLayout) findViewById(R.id.allhint);
    bOption1.setBackgroundColor(Color.parseColor("#33FF33FF"));
    bOption2.setBackgroundColor(Color.parseColor("#33FF33FF"));
    bOption3.setBackgroundColor(Color.parseColor("#33FF33FF"));
    bOption4.setBackgroundColor(Color.parseColor("#33FF33FF"));
    confirm.setBackgroundColor(Color.parseColor("#33FF33FF"));
    proceed.setBackgroundColor(Color.parseColor("#33FF33FF"));
            // getData() gets all questions from my sqlite database
    SQLView sv = databaseHelper.getData();

我希望循环从这里开始,(我可能错了!)

    answer = sv.getAnswer().toString();
    question = sv.getQuestion();
    explain = sv.getExplanation().toString();
    option1 = sv.getOption1();
    option2 = sv.getOption2();
    option3 = sv.getOption3();
    option4 = sv.getOption4();

    tvQuestion.setText(question);
    bOption1.setText(option1);
    bOption2.setText(option2);
    bOption3.setText(option3);
    bOption4.setText(option4);

    actual = bOption1.getText().toString();
    actual2 = bOption2.getText().toString();
    actual3 = bOption3.getText().toString();
    actual4 = bOption4.getText().toString();
    soption1 = 0;
    soption2 = 0;
    soption3 = 0;
    soption4 = 0;
    bOption1.setOnClickListener(ExamGround.this);
    bOption2.setOnClickListener(this);
    bOption3.setOnClickListener(this);
    bOption4.setOnClickListener(this);
    confirm.setOnClickListener(this);
}
@Override
public void onClick(View V) {
    switch (V.getId()) {
    case R.id.option1:
        soption1 = 1;
        soption2 = 0;
        soption3 = 0;
        soption4 = 0;
        bOption1.setBackgroundColor(Color.parseColor("#FFCCFFCC"));
        bOption2.setBackgroundColor(Color.parseColor("#33FF33FF"));
        bOption3.setBackgroundColor(Color.parseColor("#33FF33FF"));
        bOption4.setBackgroundColor(Color.parseColor("#33FF33FF"));
        break;
    case R.id.option2:
        soption1 = 0;
        soption2 = 1;
        soption3 = 0;
        soption4 = 0;
        bOption1.setBackgroundColor(Color.parseColor("#33FF33FF"));
        bOption2.setBackgroundColor(Color.parseColor("#FFCCFFCC"));
        bOption3.setBackgroundColor(Color.parseColor("#33FF33FF"));
        bOption4.setBackgroundColor(Color.parseColor("#33FF33FF"));
        break;
    case R.id.option3:
        soption1 = 0;
        soption2 = 0;
        soption3 = 1;
        soption4 = 0;
        bOption1.setBackgroundColor(Color.parseColor("#33FF33FF"));
        bOption2.setBackgroundColor(Color.parseColor("#33FF33FF"));
        bOption3.setBackgroundColor(Color.parseColor("#FFCCFFCC"));
        bOption4.setBackgroundColor(Color.parseColor("#33FF33FF"));
        break;
    case R.id.option4:
        soption1 = 0;
        soption2 = 0;
        soption3 = 0;
        soption4 = 1;
        bOption1.setBackgroundColor(Color.parseColor("#33FF33FF"));
        bOption2.setBackgroundColor(Color.parseColor("#33FF33FF"));
        bOption3.setBackgroundColor(Color.parseColor("#33FF33FF"));
        bOption4.setBackgroundColor(Color.parseColor("#FFCCFFCC"));
        break;
    case R.id.confirm:
        tvexplain.setText(explain);
        ahint.setVisibility(View.VISIBLE);
        proceed.setVisibility(View.VISIBLE);
        proceed.setText(continued);
        confirm.setVisibility(View.INVISIBLE);
        if(actual.equals(answer)){
            bOption1.setBackgroundColor(Color.parseColor("#FF66FF66"));
                if(soption1 == 1){
                    scores++;
                }
            }
        if(actual2.equals(answer)){
                bOption2.setBackgroundColor(Color.parseColor("#FF66FF66"));
                if(soption2 == 1){
                    scores++;
                }
            }
        if(actual3.equals(answer)){
                bOption3.setBackgroundColor(Color.parseColor("#FF66FF66"));
                if(soption3 == 1){
                    scores++;
                }
            }
        if(actual4.equals(answer)){
                bOption4.setBackgroundColor(Color.parseColor("#FF66FF66"));
                if(soption4 == 1){
                    scores++;
                }
            }
        break;
    case R.id.proceedto:
        //In here I want the loop to read next question
        break;
    }

我不知道以前是否曾经问过这个问题,我试过搜索但是现在已经超过2天了,我还没有得到任何线索。 请高度赞赏所有答案。 提前谢谢......

0 个答案:

没有答案