java如何防止RadioGroup事件?
我有一个放射组
<RadioGroup
安卓:id="@+id/typeGroup"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:orientation="horizontal">
<RadioButton
安卓:id="@+id/type0"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:checked="true"
安卓:text="type0" />
<RadioButton
安卓:id="@+id/type1"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:text="type1" />
</RadioGroup>
这是程序,我可以要求用户确认更改,如果没有,单选按钮不应该更改,是否有类似javascript默认值的功能
typeGroup=(RadioGroup)findViewById(R.id.typeGroup);
typeGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
type=group.indexOfChild((RadioButton) findViewById(checkedId));
//dialog confirm change
//if yes, keep going
//if no, stop event
}
}
);
# 1 楼答案
您可以使用警报对话框,以防用户接受,然后您进行无线电组选择,或者不进行其他操作。下面是一个例子:
我希望它对你有用