radiobutton没有给我正确的答案

时间:2014-04-05 14:36:35

标签: android radio-button radio-group

我是android的新手,我希望你能帮助我。 我开发了一个测验应用程序,涉及一个radiobutton组作为我的选择。我在oncheckchange中创建了一组问题,这是我的随机整数选择代码

的结果
public void onCheckedChanged(RadioGroup group, int checkedId) {
    int randpic= (int) (Math.random() *7);
    if (randpic==0) {
        randpic=1;
    } else if (randpic==7) {
        randpic=6;
    }
}

因此我从随机整数randpic生成我的问题集。我然后做一个案例/开关来显示我的问题。

switch (randpic) {
    case 1:
    picquest.setImageResource(R.drawable.pic1);
    difflevel.setImageResource(R.drawable.diff);
    radiobutton1.setText("Opal");
    radiobutton2.setText("Jade");
    radiobutton3.setText("Citrine");
    radiobutton4.setText("Gold");
    toastmgs = ("the most common reference for which is certain coloured varieties of 
    quartz which are a medium deep shade of golden yellow.");
    if (radiobutton1.isChecked()) {
        basicgem++;Toast.makeText(getApplicationContext(),"correct",Toast.LENGTH_LONG).show();
    Gunit.clearCheck();
    }
    else { 
        Toast.makeText(getApplicationContext(),"wrong", Toast.LENGTH_LONG).show();
    }    
    break;


    case 2:
    picquest.setImageResource(R.drawable.pic2);
    difflevel.setImageResource(R.drawable.diff);
    radiobutton1.setText("Amber");
    radiobutton2.setText("Amethyst");
    radiobutton3.setText("Azurite");
    radiobutton4.setText("Emerald");
    toastmgs = ("Azurite is a soft, deep blue copper mineral produced by weathering of copper ore deposits. It is also known as Chessylite");
    if (radiobutton3.isChecked()) {
        basicgem++;
        toast.makeText(getApplicationContext(),"correct",Toast.LENGTH_LONG).show();
        Gunit.clearCheck();  
    } else { 
        Toast.makeText(getApplicationContext(),"wrong", Toast.LENGTH_LONG).show();
    }    
    break;
}

每次我在我的设备上运行该应用程序时,在获得正确答案时,它似乎很受欢迎。大部分时间它都说"错误"虽然我按下正确的答案,然后它会说"正确"有正确的答案。我死了,你可以帮助我。提前谢谢。

更新 问题是,我的活动需要获得一个随机数来为nextQuestion选择。随机数由randpic表示,首先通过它完美的randpic选择一个数字,使用radiobutton显示问题和选项然后让你知道它是正确还是错误。下一遍,randpic选择另一个整数并显示另一张图片,遗憾的是,尽管我的clearCheck清除了radiobutton,但仍然将radiobutton卡在旧位置上。因此,我按下转到答案位置并再按一次确认答案。我在一篇文章中看到了粘性按钮一词。问题:每次按下按钮从New到旧位置randpic被触发所以现在不是验证他们的新问题,答案实际上是针对第三个问题而不是第二个问题....如何使用代码防止这个粘滞按钮我现在有。再次感谢提前。

0 个答案:

没有答案