我正在尝试在警报对话框中显示带有 2 个按钮的单选组。
我在列表项单击时动态创建对话框和警报。
除了每次显示警报时单选按钮 ID 都会增加(如果我点击取消然后重新单击列表项)之外,它工作正常。
顺便说一句,有没有比创建临时最终变量更好的方法来引用广播组?
// List item clicked
@Override
public void onItemClick(AdapterView<?> oAdapterView, View oView, int iPos, long lArg)
{
ListView oListView = (ListView) findViewById(R.id.usage_room_list_lv);
String strClickedItem = (String) oListView.getItemAtPosition(iPos);
AlertDialog.Builder oAlert = new AlertDialog.Builder(this);
oAlert.setTitle("Alert Title");
oAlert.setMessage("Alert Message");
oAlert.setNegativeButton(getResources().getString(R.string.cancel).toString(), null);
RadioGroup oGroup = new RadioGroup(this);
RadioButton oFirstButton = new RadioButton(this);
oFirstButton.setText("First Button");
RadioButton oSecondButton = new RadioButton(this);
oSecondButton .setText("Second Button");
oGroup.addView(oSecondButton);
oGroup.addView(oAccessibleChoice);
// Required for inside setPositiveButton below, is there a better way?
final RadioGroup oTmpGroup = oGroup;
oAlert.setView(oTmpGroup);
oAlert.setPositiveButton("Done", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
// This auto increments
if (DEBUG) System.out.println(CLASS_NAME + " Clicked option: " + oTmpGroup.getCheckedRadioButtonId());
}
});
oAlert.show();
}