Java 如何将RadioGroup和EditText添加到AlertDialog?
嗨,我想使用警报对话框获取用户名和用户性别,因此我添加:Java 如何将RadioGroup和EditText添加到AlertDialog?,java,android,android-alertdialog,Java,Android,Android Alertdialog,嗨,我想使用警报对话框获取用户名和用户性别,因此我添加: AlertDialog.Builder user= new AlertDialog.Builder(this); user.setTitle("New Student"); user.setMessage("What is your Name?"); final RadioGroup genderRG= new RadioGroup(this); RadioButton radiomr = new
AlertDialog.Builder user= new AlertDialog.Builder(this);
user.setTitle("New Student");
user.setMessage("What is your Name?");
final RadioGroup genderRG= new RadioGroup(this);
RadioButton radiomr = new RadioButton(this);
radiomr.setText("Mr");
// radiomr.setId(1);
genderRG.addView(radiomr);
RadioButton radiomiss = new RadioButton(this);
radiomiss.setText("Miss");
// radiomiss.setId(2);
genderRG.addView(radiomiss);
user.setView(genderRG);
final EditText input = new EditText(this);
user.setView(input);
user.setPositiveButton("OK", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int whichButton)
{
// get data
}
});
user.setNegativeButton("CANCEL", null);
user.create().show();
但当我运行它时,它只会给我一个编辑文本。
请如何使用单选按钮或微调器在同一AlertDialog中获取性别和姓名。您应该创建自己的布局并通过setView进行设置。 相反,您只是在膨胀EditText,这就是为什么您在对话框中只有它 在任何情况下,最好使用DialogFragment创建自己的对话框版本 更多