Android 带有alertDialog的单选按钮

Android 带有alertDialog的单选按钮,android,Android,我的单选按钮有问题,因为它在myLayout中显示单选组,而不是在alertDialog中。我曾尝试这样做,但我不知道如何放置它,因为我对android是全新的 View myView = getLayoutInflater().inflate(R.layout.radiogroup, null); setContentView(myView); RadioGroup myRadioGroup = (RadioGroup) myView.findViewById(R

我的单选按钮有问题,因为它在myLayout中显示单选组,而不是在alertDialog中。我曾尝试这样做,但我不知道如何放置它,因为我对android是全新的

   View myView = getLayoutInflater().inflate(R.layout.radiogroup, null);
    setContentView(myView);
    RadioGroup myRadioGroup = (RadioGroup)
    myView.findViewById(R.id.radioGroup);

    int radioGroupId = myRadioGroup.getCheckedRadioButtonId();
    RadioButton myCheckedButton = (RadioButton)
    myView.findViewById(radioGroupId);
    int index = myRadioGroup.indexOfChild(myCheckedButton);

    new AlertDialog.Builder(this)   
    .setMessage("Choose Startup Color:")
    .setPositiveButton("Set Startup Color", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
        }
     })

    .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
        }
     })

    .show();

您正在设置活动的布局,以通过执行以下操作显示放射组布局:

View myView = getLayoutInflater().inflate(R.layout.radiogroup, null);
setContentView(myView);

如果要在AlertDialog中显示该视图,可以通过在生成器上调用
setView
并将
myView
作为参数传递来设置该视图。

您忘记发布代码了。如果你能发布你的代码,我们可能会帮助你