Android AlertDialog内的RadioGroup:仅显示单个单选按钮
我正在尝试在AlertDialog中设置一个RadioGroup。我使用下面的构造Android AlertDialog内的RadioGroup:仅显示单个单选按钮,android,Android,我正在尝试在AlertDialog中设置一个RadioGroup。我使用下面的构造 new AlertDialog.Builder(this) .setTitle("Set icon for " + item_cursor.getString(1)) .setView(radioGroupView) .setPositiveButton("Ok", new DialogInterfac
new AlertDialog.Builder(this)
.setTitle("Set icon for " + item_cursor.getString(1))
.setView(radioGroupView)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radiogroup);
int checkedRadioButton = 0;
try {
checkedRadioButton = radioGroup.getCheckedRadioButtonId();
} catch (Exception e) {
e.printStackTrace();
}
int i =0;
switch (checkedRadioButton) {
case R.id.a2s :
datasource.updateIcon(i,itemid);
break;
case R.id.android: i=1;
datasource.updateIcon(i,itemid);
break;
}
}
}).setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
// Canceled.
}
}).show();
但是alertDialog只显示一个单选按钮。以下是XML seticon.XML文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal"
android:id="@+id/radiogroup">
<RadioButton android:id="@+id/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Android" />
<RadioButton android:id="@+id/a2s" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="Argen2Stone ROM" />
</RadioGroup>
</LinearLayout>
为什么会发生这种情况?尝试更改收音组和线性布局上的收音高度。您对RadioGroup的定义在哪里!!我使用的是android:orientation=“horizontal”用于
RadioGroup
。应该是android:orientation=“vertical”
请参见问题中的我的评论。如果您据此编辑您的答案,我将接受。:)