Any idea why this would crash my app when I select a radio button?
I\'ve imported android.widget.RadioGroup.OnCheckedChangeListener
, and I\'ve also trie
the problem you have is because of the onclick in your XML file so just delete the onclick in your XML attributes and implement onCheckedChangeListener like this:
priorRadioGroup=(RadioGroup)fragmentView.findViewById(R.id.priorityRadioGroup);
priorRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch(checkedId) {
//your code comes here
}
}
});
when you set onclick in Layout XML file it means you should have the method you called in activity class, and you don't. hope it helps.
You can find the cause of the crash in these lines:
java.lang.IllegalStateException: Could not find a method onRadioButtonClicked(View) in the activity class com.example.ringtones.MainActivity for onClick handler
and
Caused by: java.lang.NoSuchMethodException: onRadioButtonClicked [class android.view.View]
The problem is that you don't have a method onRadioButtonClicked
in your MainActivity
. Just declare it and you'll be fine.
Remove the android:onClick="onRadioButtonClick"
from each of your RadioButtons in XML. You should be handling the selection of the RadioButtons inside the OnCheckedChangeListener
you are setting on the RadioGroup.
If you need to do special processing when a particular RadioButton is selected, you can use a switch
statement inside of the onCheckedChanged
callback - the checkedId
argument is the android:id
value of the selected RadioButton (or -1 if the selection is cleared).