Android radio group onCheckChangedListener crashing app

前端 未结 3 1899
走了就别回头了
走了就别回头了 2020-12-20 08:20

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

3条回答
  •  无人及你
    2020-12-20 09:17

    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).

提交回复
热议问题