繁体   English   中英

如何避免在WebView页面加载完成时持续发出警报?Android

[英]How to avoid continuous alert on WebView Page Loading Finished?Android

我有一个Webview,因为我在Webview页面加载完成时给出了一些说明页面

这是我的示例代码

public void onPageFinished(WebView view, String url) {

if (!getSharedPreferences("MainA_SP", MODE_PRIVATE)
        .getBoolean("checkbox", false)) {

    AlertDialog.Builder adb=new AlertDialog.Builder(MainA.this);
    LayoutInflater adbInflater = LayoutInflater.from(MainA.this);
    View eulaLayout = adbInflater.inflate(R.layout.instpopup, null);
    chkbx = (CheckBox)eulaLayout.findViewById(R.id.skip);
    adb.setView(eulaLayout);
    adb.setTitle("Welcome To Sample Page");
    adb.setMessage(Html.fromHtml("App Instructions ....."));
    adb.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String checkBoxResult = "NOT checked";
            if (chkbx.isChecked())  checkBoxResult = "checked";
            SharedPreferences settings = getSharedPreferences(MainA_SP, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString("skipMessage", checkBoxResult);
            // Commit the edits!
            editor.commit();
            return;
        } });

    adb.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String checkBoxResult = "NOT checked";
            if (chkbx.isChecked())  checkBoxResult = "checked";
            SharedPreferences settings = getSharedPreferences(MainA_SP, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString("skipMessage", checkBoxResult);
            // Commit the edits!
            editor.commit();
            return;
        } });
    SharedPreferences settings = getSharedPreferences(MainA_SP, 0);
    String skipMessage = settings.getString("skipMessage", "NOT checked");
    if (!skipMessage.equalsIgnoreCase("checked") ) adb.show();
}

try{
    if (progressBar.isShowing()) {
        progressBar.dismiss();
      .
      .
      .
      .

    }
}catch(Exception exception){
    exception.printStackTrace();
}
}

所以在这里它可以与Checkbox和sharedprefs一起正常工作

但是问题是我已经在页面加载完成时给出了此警报,所以我对单个网址单个页面获得了多次警报

我每次打开应用程序时都需要单击警报...如果我勾选复选框,则它不会显示,但首次运行时,警报会显示多次

更新资料

我想在页面上显示警报成功完成加载

如果要在完成后立即显示警报,则可以使用布尔值来检查它是否可见,如下面的示例所示。

 private boolean alertVisiblity = false;

onPageFinished(){

//show your alert here
if(!alertVisiblity){
 alertVisiblity = true;
new AlertDialog.Builder(MainActivity.this)
                .setCancelable(false)
                .setTitle("Alert")
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                        alertVisiblity = false; //or if you want to show it once never make it false or you can make it false before next call
                    }
                }).show();


}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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