public void showDialog(Activity activity) {
final CharSequence[] items = {" No timer ", " 1 minute ", " 3 minute ", " 5 minute ", "10 minute"};
// Creating and Building the Dialog
AlertDialog.Builder builder = new AlertDialog.Builder(AutumnForest.this);
builder.setTitle("Set timer duration");
builder.setSingleChoiceItems(items, selection, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int item) {
switch (item) {
case 0:
if (isRunning) {
count_down_timer.cancel();
_tv.setVisibility(View.INVISIBLE);
gong_imageview.setVisibility(View.INVISIBLE);
timer_imageview.setImageResource(R.drawable.time_icon);
}
dialog.dismiss();
break;
case 1:
// if timer is running somewhere
if (!isRunning) {
isRunning = true;
countDownTimer(item);
levelDialog.dismiss();
} else {
count_down_timer.cancel();
countDownTimer(item);
levelDialog.dismiss();
}
break;
case 2:
if (!isRunning) {
isRunning = true;
countDownTimer(item);
levelDialog.dismiss();
} else {
count_down_timer.cancel();
countDownTimer(item);
levelDialog.dismiss();
}
break;
case 3:
if (!isRunning) {
isRunning = true;
countDownTimer(item);
} else {
count_down_timer.cancel();
countDownTimer(item);
levelDialog.dismiss();
}
break;
case 4:
if (!isRunning) {
isRunning = true;
countDownTimer(item);
} else {
count_down_timer.cancel();
countDownTimer(item);
levelDialog.dismiss();
}
break;
case 5:
if (!isRunning) {
isRunning = true;
countDownTimer(item);
} else {
count_down_timer.cancel();
countDownTimer(item);
levelDialog.dismiss();
}
break;
default:
Toast.makeText(AutumnForest.this, "Something went wrong please try again", Toast.LENGTH_SHORT).show();
}
}
});
levelDialog = builder.create();
levelDialog.show();
}
代码运行良好但是当点击发生时,它会保留到案例1而不是单击的项目。 我希望如果我点击案例3或4这样的东西应该是setchecked = true和其他setchecked = false但它没有显示。
这是我得到的输出。
答案 0 :(得分:0)
尝试使用:
switch (item) {
case item[0]:
case item[1]:
...........