button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (R.id.radioButton == checked) Toast toast = Toast.makeText(getApplicationContext(), "Правильно", Toast.LENGTH_LONG); }else { Toast toast = Toast.makeText(getApplicationContext(), "Неправильно", Toast.LENGTH_LONG); } }); } // Почему checked ошибка???Как мне выбрать ??? - Because you compare int with bollean. This IDE itself should even tell you - YurySPb ♦
|
1 answer
Your line of code
if(R.id.radioButton == checked) incomprehensible. You compare type int with a certain variable checked . Since your variable is not initialized, the compiler gives an error. In general, if you want to check if a RadioButton is RadioButton , then you need to do it this way.
RadioButton rb = (RadioButton)findViewById(R.id.radioButton); if(rb.isChecked()) //если выбрана |