Looking at the published XML, try the following:
Context context=LocationActivity.this; dialog=new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); View view = LayoutInflater.fromContext(context).inflate(R.layout.custom_dialog, null, false); RadioGroup rg = (RadioGroup) view.findViewById(R.id.radiogroup); RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams( RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT); // add 5 radio buttons to the group RadioButton rb; for (int i = 0; i < 5; i++){ rb = new RadioButton(context); rb.setText("item set" + i); rb.setId(i); rg.addView(rb, layoutParams); } dialog.setContentView(view);
I did not see how you changed your dialogue. So I inflated the layout, added RadioButtons, and then passed the completed layout to the dialog .
Also, since linearMain has only one child, you can remove this LinearLayout and just use radioGroup .
source share