我正在尝试在警告对话框中添加自定义单选按钮。现在我想添加监听器。我试图使用Radio组添加侦听器,但它显示空指针异常。 这是我的代码。请如何添加监听器,我想在点击任何单选按钮
时关闭对话框 final AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
LayoutInflater eulaInflater = LayoutInflater.from(this);
View eulaLayout = eulaInflater.inflate(R.layout.alertdialogcustom, null);
alt_bld.setView(eulaLayout);
RadioGroup rgroup = (RadioGroup)findViewById(R.id.group1);
由于 Astha
答案 0 :(得分:1)
我自己使用Dialog
得到它 dialog.setContentView(R.layout.alertdialogcustom);
dialog.setTitle("This is my custom dialog box");
dialog.setCancelable(true);
final RadioGroup rgroup = (RadioGroup)dialog.findViewById(R.id.group1);
final RadioButton rbutton_series = (RadioButton) dialog.findViewById(R.id.option1);
final RadioButton rbutton_overlay = (RadioButton) dialog.findViewById(R.id.option2);
rgroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()