gpt4 book ai didi

java - 如何检查警报对话框的可见性?

转载 作者:行者123 更新时间:2023-12-01 20:27:23 24 4
gpt4 key购买 nike

我想检查警报对话框是否可见。在大多数帖子中我看到他们使用了 isShowing,但现在似乎无法描述。

当用户单击信息 TextView 时,我暂停音乐。如果用户关闭警报对话框,音乐将再次播放。

info_Button.setClickable(true);
info_Button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mediaControl.pause();
AlertDialog.Builder playstopbutton_builder = new AlertDialog.Builder(exercise_arm_triceps_execute.this);
playstopbutton_builder.setTitle("WARNING").setMessage("Please get warm before exercising!");
playstopbutton_builder.create().show();
playstopbutton_builder.setCancelable(false);

//if alert dialog is visible keep music paused
//else if mediaControl.start();

}
});

最佳答案

由于您已将 Cancelable 设置为 false,因此您可能需要使用

对于积极按钮,请说“好”

playstopbutton_builder.setPositiveButton(positiveBtnText,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
//resume ur media player here
}
})

否定按钮如取消

playstopbutton_builder.setNegativeButton(negativeBtnText,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
//resume ur media player here
}
})

所以看起来像这样

info_Button.setClickable(true);
info_Button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mediaControl.pause();
AlertDialog.Builder playstopbutton_builder = new AlertDialog.Builder(exercise_arm_triceps_execute.this);
playstopbutton_builder.setTitle("WARNING").setMessage("Please get warm before exercising!");
playstopbutton_builder.create().show();
playstopbutton_builder.setCancelable(false);
playstopbutton_builder.setPositiveButton(positiveBtnText,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
//resume ur media player here
}
});
playstopbutton_builder.setNegativeButton(negativeBtnText,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
//resume ur media player here
}
});
}
});

关于java - 如何检查警报对话框的可见性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43668559/

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