ラジオボタンを含むアラートダイアログがあります。ユーザーがそれらのいずれかをクリックすると、アラートダイアログが停止します。
そのため、肯定ボタンや否定ボタンはなく、ラジオボタンの 1 つをクリックするだけでアラート ダイアログが閉じます。
しかし、私は方法がわかりません:
ユーザーがラジオボタンをクリックしたときにアラートダイアログを閉じる
アラートダイアログが閉じられた後、クリックされたラジオボタンを撤回します
これがコードです。
public void createAlerDialogRadioButton(String title, String[] radiobuttontitles)
{
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
RadioGroup rbg = new RadioGroup(this);
alertDialog.setTitle(title);
int nbbutton = radiobuttontitles.length;
// add a radiobutton to the radiogroup for each element of radiobuttontitles
for (int i=0;i<nbbutton;i++) {
RadioButton mrd = new RadioButton(this);
mrd.setText(radiobuttontitles[i]);
rbg.addView(mrd);
}
// the view
TextView textView = new TextView(this);
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT));
linearLayout.setOrientation(1);
linearLayout.addView(textView);
linearLayout.addView(rbg);
alertDialog.setView(linearLayout);
alertDialog.show();
}
ご協力いただきありがとうございます。