gpt4 book ai didi

android - 如何启用或禁用android中的复选框

转载 作者:太空狗 更新时间:2023-10-29 16:21:54 24 4
gpt4 key购买 nike

我的快速警报对话框中有 4 个复选框...我想要的是,当我选中 [启用] 1 个复选框时,其他 3 个复选框必须禁用。我点击了它们,但没有禁用它们。我不知道该怎么做。

这是我要找的:

mockup

    checkmrn  =  (CheckBox) container.findViewById(R.id.MrnCheckBox);
checkmrn.setText("By Mrn");
checkmrn.setEnabled(false);
checkdate = (CheckBox) container.findViewById(R.id.dateCheckBox);
checkdate.setText("By Date");
checkname = (CheckBox) container.findViewById(R.id.nameCheckBox);
checkname.setText("By Name");
checklocation = (CheckBox) container.findViewById(R.id.locationCheckBox);
checklocation.setText("By Location");
okButton = (Button) container.findViewById(R.id.okButton);
okButton.setText("Ok");

checkmrn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
Toast.makeText(mContext, "By Mrn", Toast.LENGTH_SHORT).show();
}
}
});
checkdate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
Toast.makeText(mContext, "By Date", Toast.LENGTH_SHORT).show();
}
}
});
checkname.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
Toast.makeText(mContext, "By Name", Toast.LENGTH_SHORT).show();
}
}
});
checklocation.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
Toast.makeText(mContext, "By Location", Toast.LENGTH_SHORT).show();
}
}
});

最佳答案

这是上述问题的工作代码。

  checkmrn  =  (CheckBox) container.findViewById(R.id.MrnCheckBox);
checkmrn.setText("By Mrn");
checkdate = (CheckBox) container.findViewById(R.id.dateCheckBox);
checkdate.setText("By Date");
checkname = (CheckBox) container.findViewById(R.id.nameCheckBox);
checkname.setText("By Name");
checklocation = (CheckBox) container.findViewById(R.id.locationCheckBox);
checklocation.setText("By Location");

okButton = (Button) container.findViewById(R.id.okButton);
okButton.setText("Ok");

checkmrn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

if (((CheckBox) v).isChecked()) {
checkmrn.setChecked(true);
Toast.makeText(mContext, "By Mrn", Toast.LENGTH_SHORT).show();
checkdate.setChecked(false);
checkname.setChecked(false);
checklocation.setChecked(false);
}
}
});
checkdate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
checkdate.setChecked(true);
Toast.makeText(mContext, "By Date", Toast.LENGTH_SHORT).show();
checkmrn.setChecked(false);
checkname.setChecked(false);
checklocation.setChecked(false);
}
}
});
checkname.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
checkname.setChecked(true);
Toast.makeText(mContext, "By Name", Toast.LENGTH_SHORT).show();
checkmrn.setChecked(false);
checkdate.setChecked(false);
checklocation.setChecked(false);
}
}
});
checklocation.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

if (((CheckBox) v).isChecked()) {
checklocation.setChecked(true);
Toast.makeText(mContext, "By Location", Toast.LENGTH_SHORT).show();
checkmrn.setChecked(false);
checkname.setChecked(false);
checkdate.setChecked(false);
}
}
});
checkmrn = (CheckBox) container.findViewById(R.id.MrnCheckBox);
checkmrn.setText("By Mrn");
checkdate = (CheckBox) container.findViewById(R.id.dateCheckBox);
checkdate.setText("By Date");
checkname = (CheckBox) container.findViewById(R.id.nameCheckBox);
checkname.setText("By Name");
checklocation = (CheckBox) container.findViewById(R.id.locationCheckBox);
checklocation.setText("By Location");

okButton = (Button) container.findViewById(R.id.okButton);
okButton.setText("Ok");

checkmrn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

if (((CheckBox) v).isChecked()) {
checkmrn.setChecked(true);
Toast.makeText(mContext, "By Mrn", Toast.LENGTH_SHORT).show();
checkdate.setChecked(false);
checkname.setChecked(false);
checklocation.setChecked(false);
}
}
});
checkdate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
checkdate.setChecked(true);
Toast.makeText(mContext, "By Date", Toast.LENGTH_SHORT).show();
checkmrn.setChecked(false);
checkname.setChecked(false);
checklocation.setChecked(false);
}
}
});
checkname.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
checkname.setChecked(true);
Toast.makeText(mContext, "By Name", Toast.LENGTH_SHORT).show();
checkmrn.setChecked(false);
checkdate.setChecked(false);
checklocation.setChecked(false);
}
}
});
checklocation.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

if (((CheckBox) v).isChecked()) {
checklocation.setChecked(true);
Toast.makeText(mContext, "By Location", Toast.LENGTH_SHORT).show();
checkmrn.setChecked(false);
checkname.setChecked(false);
checkdate.setChecked(false);
}
}
});

关于android - 如何启用或禁用android中的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12422456/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com