你好,我是 Android 初学者。我在我的项目中使用了四个复选框。我想在 3 号和 4 号复选框处于未选中状态后调用一种方法。如何编写该代码请帮助我。
提前致谢。
class myCheckBoxChnageClicker implements CompoundButton.OnCheckedChangeListener {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// Is the view now checked?
boolean checked = ((CheckBox) buttonView).isChecked();
// Check which checkbox was clicked
switch(buttonView.getId()) {
case R.id.t3_check:
if (checked) {
} else {
}
break;
case R.id.t4_check:
if (checked) {
} else {
}
break;
case R.id.tsh_check:
if (checked) {
} else {
}
break;
case R.id.weight_check:
if(checked) {
} else {
}
break;
default:
}
}
public void showTextNotification(String msgToDisplay) {
if ((msgToDisplay.equals("Tsh_Check") && msgToDisplay.equals("Weight_Check"))) {
Toast.makeText(getApplicationContext(), "match", Toast.LENGTH_SHORT).show();
} else {
}
}
}
您好,这是我的代码,当 3 和 4 复选框处于未选中状态时,我想调用 showTextNotification()
方法。
最佳答案
试试这个。
final boolean Check_three = false;
final boolean Check_foure = false;
class myCheckBoxChnageClicker implements CompoundButton.OnCheckedChangeListener {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// Is the view now checked?
boolean checked = ((CheckBox) buttonView).isChecked();
// Check which checkbox was clicked
switch(buttonView.getId()) {
case R.id.t3_check:
if (checked) {
Check_three = true;
if (Check_three == true && Check_foure == true)
{
showTextNotification("printmeaage");
}
} else {
Check_three = false;
}
break;
case R.id.t4_check:
if (checked) {
Check_foure = true;
if (Check_three == true && Check_foure == true)
{
showTextNotification("printmeaage");
}
} else {
Check_foure = false;
}
break;
case R.id.tsh_check:
if (checked) {
} else {
}
break;
case R.id.weight_check:
if(checked) {
} else {
}
break;
default:
}
}
关于android - 如何在android中选中两个未选中的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47300801/