我有一个警告对话框,当互联网连接不存在时会显示。我删除了“确定”按钮,以便用户无法关闭它。但是如果互联网状态已经变为开启状态,如何关闭它呢?!
这是我的警报对话框的代码:
public void showAlertDialog(Context context, String title, String message, Boolean status) {
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
// Setting Dialog Title
alertDialog.setTitle(title);
// Setting Dialog Message
alertDialog.setMessage(message);
// Setting alert dialog icon
alertDialog.setIcon((status) ? R.drawable.success : R.drawable.fail);
// Showing Alert Message
alertDialog.show();
}
我是这样调用它的:
// check for Internet status
if (isInternetPresent) {
// Internet Connection is Present
// make HTTP requests
switch (v.getId()) {
case R.id.btn_login:
new AttemptLogin().execute();
default:
break;
}
} else {
// Internet connection is not present
// Ask user to connect to Internet
showAlertDialog(Login.this, "No Internet Connection",
"You don't have internet connection.", false);
}
最佳答案
尝试使用监听ConnectivityManager.CONNECTIVITY_ACTION
的BroadcastReciver
。
关于java - 如何设置警报对话框打开直到状态更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29036839/