大家好我正在尝试编写一个程序来检查我所有的无线电按钮是否都没有被选中,并打印“抱歉你必须在继续之前选择一个单选按钮”。我已经打印出该消息,但是当我弹出该消息后选择一个单选按钮时,我仍然会收到“抱歉,你必须继续......”的消息。
以下是我的想法:
no = (Button) findViewById(R.id.next);
no.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
RadioButton r1 = (RadioButton) findViewById(R.id.radioButton);
RadioButton r2 = (RadioButton) findViewById(R.id.radioButton2);
RadioButton r3 = (RadioButton) findViewById(R.id.radioButton3);
RadioButton r4 = (RadioButton) findViewById(R.id.radioButton4);
RadioButton r5 = (RadioButton) findViewById(R.id.radioButton5);
if(!(r1.isChecked() || r2.isChecked()) || r3.isChecked() || r4.isChecked() || r5.isChecked())
{
riskLevel = Question1Activity.countPoints;
if(riskLevel >= 6 && riskLevel <= 9)
{
Toast.makeText(Question7Activity.this, "High Risk", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(v.getContext(), HighRiskActivity.class);
startActivity(intent);
}
if(riskLevel >= 3 && riskLevel <= 5)
{
Toast.makeText(Question7Activity.this, "Moderate Risk" , Toast.LENGTH_SHORT).show();
}
if(riskLevel >= 1 && riskLevel <= 2)
{
Toast.makeText(Question7Activity.this, "Low Risk", Toast.LENGTH_SHORT).show();
}
if(riskLevel == 0)
{
Toast.makeText(Question7Activity.this, "No Risk", Toast.LENGTH_SHORT).show();
}
}else
{
Toast.makeText(Question7Activity.this, "Well buddy nice try", Toast.LENGTH_SHORT).show();
}
}
});
我知道这很简单,但我想不出可能出现什么问题。
-Thanks!
答案 0 :(得分:0)
if((r1.isChecked() || r2.isChecked()) || r3.isChecked() || r4.isChecked() || r5.isChecked())
{
riskLevel = Question1Activity.countPoints;
if(riskLevel >= 6 && riskLevel <= 9)
{
Toast.makeText(Question7Activity.this, "High Risk", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(v.getContext(), HighRiskActivity.class);
startActivity(intent);
}
if(riskLevel >= 3 && riskLevel <= 5)
{
Toast.makeText(Question7Activity.this, "Moderate Risk" , Toast.LENGTH_SHORT).show();
}
if(riskLevel >= 1 && riskLevel <= 2)
{
Toast.makeText(Question7Activity.this, "Low Risk", Toast.LENGTH_SHORT).show();
}
if(riskLevel == 0)
{
Toast.makeText(Question7Activity.this, "No Risk", Toast.LENGTH_SHORT).show();
}
}else {
Toast.makeText(Question7Activity.this, "Well buddy nice try", Toast.LENGTH_SHORT).show();
}
啊我修好了我必须从isChecked()条件前删除not符号。