I added a radio button group to a layout in my project, and on the fragment of this layout I did on this a listener (I use binding). "radioDen" is my radio button group name:
mBinding.radioDen.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
switch(checkedId) {
case R.id.radio_den_circle:
mBinding.setDiameterVisibility(true);
mBinding.setHeightVisibility(false);
mBinding.setWidthVisibility(false);
break;
case R.id.radio_den_none:
mBinding.setDiameterVisibility(false);
mBinding.setHeightVisibility(false);
mBinding.setWidthVisibility(false);
break;
case R.id.radio_den_rectangle:
mBinding.setDiameterVisibility(false);
mBinding.setHeightVisibility(true);
mBinding.setWidthVisibility(true);
break;
}
}
});
But when I choose one of the radio buttons -the project fall, even though that it came to the listener to the right place. When I looked in radio button -android developers , I see that I have to call in the activity to
public void onRadioButtonClicked(View view) {
}
So I just added it like this without any code inside and now it doesn't fall any more, and it keep coming like before to the listener in the fragment.
What is the reason to this problem? Is it a bug of Android? Do you know about another solution? It is just ridiculous to leave it like this...
I checked it now I removed from main activity the function and I do get a fatal error:
FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not find method onRadioButtonClicked(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatRadioButton with id 'radio_den_rectangle'"