How to check if a radiobutton is checked in a radiogroup in Android?

后端 未结 10 2139

I need to set validation that user must fill / select all details in a page. If any fields are empty wanna show Toast message to fill. Now I need set validation

10条回答
  •  春和景丽
    2020-12-04 13:39

      rgrp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                switch(i) {
                    case R.id.type_car:
                        num=1;
                        Toast.makeText(getApplicationContext()," Car",Toast.LENGTH_LONG).show();
                        break;
                    case R.id.type_bike:
                        num=2;
                        Toast.makeText(getApplicationContext()," Bike",Toast.LENGTH_LONG).show();
                        break;
                }
            }
        });
    

提交回复
热议问题