Android radio group onCheckChangedListener crashing app

前端 未结 3 1853
走了就别回头了
走了就别回头了 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:00

    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.

提交回复
热议问题