RadioGroup onCheckedChanged function won't fire

依然范特西╮ 提交于 2019-12-05 13:18:24

You are already getting checkedId as a parameter, the unique identifier of the newly checked radio button.

public void onCheckedChanged(RadioGroup group, int checkedId) {
    rbLunchOnly.setText("Click!");
    Toast.makeText(getApplicationContext(), "Lunch Only", Toast.LENGTH_LONG).show();

    switch(checkedId){
    case R.id.RadioBoth :
        populateAllShifts();
        break;

    //--other cases---

   }

Found the problem, and the answer wasn't visible from the info I gave in my question. The problem was cruft.

This started as my first project, and in a ham-handed attempt to solve a database problem months ago, I had extraneously overridden onStart() and onRestart() with pretty much the same code in onCreate(). onCreate has changed over time, and those methods did not. Once I deleted them, the code worked perfectly.

I hadn't shown those methods in the question. Sorry!

Thanks everyone for your help! What should I do now? Delete the question?

you should use this method:

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 
{
    if(isChecked == true)
    {           
        if(buttonView == radioA)            
            tvInfo.setText("A");
        else if(buttonView == radioB)               
            tvInfo.setText("B");        
        else if(buttonView == radioC)           
            tvInfo.setText("C");
    }
}

it should work.. in ur xml. u can give that clickable option for radiobuttons by android:clickable="true" in java..

public void onCheckedChanged(RadioGroup group, int checkedId) {
    switch(checkedId){
    case R.id.RadioBoth :
        populateAllShifts();
        break;
case R.id.RadioDinnerOnly:
        populatDinnerShifts();
        break;
    //-----
default:

break;
   }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!