0
皆さん私は、私が持っているすべてのラジオボタンが選択されていないかどうかをチェックするプログラムを書こうとしており、「続行する前にラジオボタンを選択しなければなりません。私はそのメッセージを印刷しましたが、そのメッセージがポップアップした後にラジオボタンを選択すると、「Sorry you must continue ...」というメッセージが表示されます。ここでRadioButtonsが選択されているかどうか
は私が作ってみたものです:
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!
「RadioButton」の中から1つだけを選択しなければならない場合は、 'RadioGroup'を使用することをお勧めします – Apoorv