简体   繁体   中英

how to set alert dialog box open until status change

I have a alert dialog box that shows when internet connection is not present. I remove the 'ok' button so that the user can't dismiss it. But how to close it if the status of the internet has been change to on?!

here is my code to my alert dialog box:

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();
}

here's how i call it:

// 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_ACTIONBroadcastReciver

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM