当我尝试在一组两个单选按钮上实现setOnCheckedListener的代码时,我的应用程序崩溃

时间:2018-11-08 01:31:13

标签: performance android-intent

我正在尝试实现代码来为两个单选按钮组设置侦听器 这是使我的应用崩溃的代码

genderOption.setOnCheckedChangeListener(
//anonymous class
    new RadioGroup.OnCheckedChangeListener() {

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
//referencing an object to retrieve Id
        RadioButton rb = (RadioButton)radioGroup.findViewById(checkedId);
        switch (rb.getId()){
              case R.id.rbMale:
                  maleGender.setText("Boy");
                  break;
              case R.id.rbFemale:
                  femaleGender.setText("Girl");
                  break;
          }
//end of switch
    }
    });
/*End of listening to clicks on radio buttons*/

0 个答案:

没有答案