Здравствуйте! Помогите, пожалуйста, разобраться...
Пишу для себя программу-тестирование по Java-вопросам. В тесте необходимо реализовать функцию нескольких правильных вариантов ответа (чекбоксы). Однако постоянно что-то не так. Сейчас например, при проверке, сразу засчитываются все варианты ответа как правильные (checkBox1Status = true;).
public void onClick(View v) {
switch (v.getId())
{
case R.id.checkBox:
if (checkBox1.isChecked() == true && (checkBox1.getText().equals(writeAnswer1) ||
checkBox1.getText().equals(writeAnswer2) ||
checkBox1.getText().equals(writeAnswer3) ||
checkBox1.getText().equals(writeAnswer4)))
{
checkBox1Status = true;
}
else if((checkBox1.isChecked() == false && !checkBox1.getText().equals(writeAnswer1)) ||
(checkBox1.isChecked() == false && !checkBox1.getText().equals(writeAnswer2)) ||
(checkBox1.isChecked() == false && !checkBox1.getText().equals(writeAnswer3)) ||
(checkBox1.isChecked() == false && !checkBox1.getText().equals(writeAnswer4))
)
{
checkBox1Status = true;
}
else if((checkBox1.isChecked() == true && !checkBox1.getText().equals(writeAnswer1)) ||
(checkBox1.isChecked() == true && !checkBox1.getText().equals(writeAnswer2)) ||
(checkBox1.isChecked() == true && !checkBox1.getText().equals(writeAnswer3)) ||
(checkBox1.isChecked() == true && !checkBox1.getText().equals(writeAnswer4))
)
{
checkBox1Status = false;
}
else if((checkBox1.isChecked() == false && checkBox1.getText().equals(writeAnswer1)) ||
(checkBox1.isChecked() == false && checkBox1.getText().equals(writeAnswer2)) ||
(checkBox1.isChecked() == false && checkBox1.getText().equals(writeAnswer3)) ||
(checkBox1.isChecked() == false && checkBox1.getText().equals(writeAnswer4)))
{
checkBox1Status = false;
}
if ((checkBox2.isChecked() == true && checkBox2.getText().equals(writeAnswer1)) ||
(checkBox2.isChecked() == true && checkBox2.getText().equals(writeAnswer2)) ||
(checkBox2.isChecked() == true && checkBox2.getText().equals(writeAnswer3)) ||
(checkBox2.isChecked() == true && checkBox2.getText().equals(writeAnswer4))
)
{
checkBox2Status = true;
}
else if((checkBox2.isChecked() == false && !checkBox2.getText().equals(writeAnswer1)) ||
(checkBox2.isChecked() == false && !checkBox2.getText().equals(writeAnswer2)) ||
(checkBox2.isChecked() == false && !checkBox2.getText().equals(writeAnswer3)) ||
(checkBox2.isChecked() == false && !checkBox2.getText().equals(writeAnswer4))
)
{
checkBox2Status = true;
}
else if((checkBox2.isChecked() == true && !checkBox2.getText().equals(writeAnswer1)) ||
(checkBox2.isChecked() == true && !checkBox2.getText().equals(writeAnswer2)) ||
(checkBox2.isChecked() == true && !checkBox2.getText().equals(writeAnswer3)) ||
(checkBox2.isChecked() == true && !checkBox2.getText().equals(writeAnswer4))
)
{
checkBox2Status = false;
}
else if((checkBox2.isChecked() == false && checkBox2.getText().equals(writeAnswer1)) ||
(checkBox2.isChecked() == false && checkBox2.getText().equals(writeAnswer2)) ||
(checkBox2.isChecked() == false && checkBox2.getText().equals(writeAnswer3)) ||
(checkBox2.isChecked() == false && checkBox2.getText().equals(writeAnswer4)))
{
checkBox2Status = false;
}
if ((checkBox3.isChecked() == true && checkBox3.getText().equals(writeAnswer1)) ||
(checkBox3.isChecked() == true && checkBox3.getText().equals(writeAnswer2)) ||
(checkBox3.isChecked() == true && checkBox3.getText().equals(writeAnswer3)) ||
(checkBox3.isChecked() == true && checkBox3.getText().equals(writeAnswer4))
)
{
checkBox3Status = true;
}
else if((checkBox3.isChecked() == false && !checkBox3.getText().equals(writeAnswer1)) ||
(checkBox3.isChecked() == false && !checkBox3.getText().equals(writeAnswer2)) ||
(checkBox3.isChecked() == false && !checkBox3.getText().equals(writeAnswer3)) ||
(checkBox3.isChecked() == false && !checkBox3.getText().equals(writeAnswer4))
)
{
checkBox3Status = true;
}
else if((checkBox3.isChecked() == true && !checkBox3.getText().equals(writeAnswer1)) ||
(checkBox3.isChecked() == true && !checkBox3.getText().equals(writeAnswer2)) ||
(checkBox3.isChecked() == true && !checkBox3.getText().equals(writeAnswer3)) ||
(checkBox3.isChecked() == true && !checkBox3.getText().equals(writeAnswer4))
)
{
checkBox3Status = false;
}
else if((checkBox3.isChecked() == false && checkBox3.getText().equals(writeAnswer1)) ||
(checkBox3.isChecked() == false && checkBox3.getText().equals(writeAnswer2)) ||
(checkBox3.isChecked() == false && checkBox3.getText().equals(writeAnswer3)) ||
(checkBox3.isChecked() == false && checkBox3.getText().equals(writeAnswer4)))
{
checkBox3Status = false;
}
if ((checkBox4.isChecked() == true && checkBox4.getText().equals(writeAnswer1)) ||
(checkBox4.isChecked() == true && checkBox4.getText().equals(writeAnswer2)) ||
(checkBox4.isChecked() == true && checkBox4.getText().equals(writeAnswer3)) ||
(checkBox4.isChecked() == true && checkBox4.getText().equals(writeAnswer4))
)
{
checkBox4Status = true;
}
else if((checkBox4.isChecked() == false && !checkBox4.getText().equals(writeAnswer1)) ||
(checkBox4.isChecked() == false && !checkBox4.getText().equals(writeAnswer2)) ||
(checkBox4.isChecked() == false && !checkBox4.getText().equals(writeAnswer3)) ||
(checkBox4.isChecked() == false && !checkBox4.getText().equals(writeAnswer4))
)
{
checkBox4Status = true;
}
else if((checkBox4.isChecked() == true && !checkBox4.getText().equals(writeAnswer1)) ||
(checkBox4.isChecked() == true && !checkBox4.getText().equals(writeAnswer2)) ||
(checkBox4.isChecked() == true && !checkBox4.getText().equals(writeAnswer3)) ||
(checkBox4.isChecked() == true && !checkBox4.getText().equals(writeAnswer4))
)
{
checkBox4Status = false;
}
else if((checkBox4.isChecked() == false && checkBox4.getText().equals(writeAnswer1)) ||
(checkBox4.isChecked() == false && checkBox4.getText().equals(writeAnswer2)) ||
(checkBox4.isChecked() == false && checkBox4.getText().equals(writeAnswer3)) ||
(checkBox4.isChecked() == false && checkBox4.getText().equals(writeAnswer4)))
{
checkBox4Status = false;
}
if (checkBox1Status==true && checkBox2Status==true && checkBox3Status==true && checkBox4Status==true)
{
Toast toast1 = Toast.makeText(getApplicationContext(),
"Верно!", Toast.LENGTH_SHORT);
toast1.show();
Intent intent = new Intent(MultyChoise.this, MainActivity.class);
startActivity(intent);
}
break;
Подскажите, пожалуйста, что не так?