Android 一次只选择一个单选按钮
当我点击Android 一次只选择一个单选按钮,android,Android,当我点击TextViewreference时,我得到了AlertDialogbuilder,因为我用单选按钮显示了employeesNames。现在,当我选中错误的员工并想选择另一名员工时,应该取消选中错误的员工姓名,通过选择一名员工,应该启用确定按钮 delivery.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {
TextView
reference时,我得到了AlertDialog
builder,因为我用单选按钮显示了employeesNames
。现在,当我选中错误的员工
并想选择另一名员工
时,应该取消选中错误的员工
姓名,通过选择一名员工
,应该启用确定
按钮
delivery.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater inflater1 = (LayoutInflater) ct.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v1 = inflater1.inflate(R.layout.activity_employees_list_for_pop_up, null);
RadioButton employeechecked = (RadioButton) v1.findViewById(R.id.employeeChecked);
final Button ok = (Button) v1.findViewById(R.id.do_ok);
Button cancle = (Button) v1.findViewById(R.id.do_cancle);
ok.setEnabled(false);
listView = (ListView) v1.findViewById(R.id.employeePopUpList);
employeePopUpAdapter = new EmployeePopUpAdapter(ct, employeeIdNameBeans);
employeechecked.setOnCheckedChangeListener(new );
listView.setAdapter(employeePopUpAdapter);
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder = new AlertDialog.Builder(ct, android.R.style.Theme_Material_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(ct);
}
builder.setView(v1);
builder.create().show();
clearListView();
update();
}
});
请帮助我进行编码。不要发表我不理解的理论。我是初学者。你可以尝试使用RadioGroup而不是RadioButton
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/a"
android:onClick="onRGClick">
<RadioButton
android:text="Normal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/a1" />
<RadioButton
android:text="Tidak normal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/a2" />
</RadioGroup>
您必须使用RadioGroup,或者通过编程来处理它。我如何才能将RadioGroup用于listview?请将问题再读一遍,这样您就可以使用android checkable listview了
radiogroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.a1) {
// do your stuff
} else if (checkedId == R.id.a2) {
// do your stuff
}
}
});