【问题标题】:Dialog not working with webview对话框不适用于 webview
【发布时间】:2013-04-25 06:17:40
【问题描述】:

我的应用程序有一个 webview,当用户没有输入正确的用户名和密码时,会弹出一个警告对话框并告诉他。

我的 Webview 接口类是:

public class WebAppInterface extends FragmentActivity{
Context mContext;
/** Instantiate the interface and set the context */
WebAppInterface(Context c) {
    mContext = c;
}

/** Show a toast from the web page */
@JavascriptInterface
public void showToast(String text) {
    Toast.makeText(mContext, text, Toast.LENGTH_SHORT).show();
}

public void showErrorDialog(String text) {
    DialogFragment dialogFragment = new ErrorDialog();
    dialogFragment.show(getSupportFragmentManager(), "errorDialog");
    }
}

而我的 Dialgofragmenct 类是:

public class ErrorDialog extends DialogFragment{

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("שגיאה");
    builder.setMessage("טקסט כלשהו");
    builder.setPositiveButton("אישור", new OnClickListener() {      
        public void onClick(DialogInterface dialog, int which) {
            dismiss();
        }
    });
    builder.setCancelable(false);
    return builder.create();
}

}

当我在eclipse上运行调试器时,界面中的方法showErrorDialog()有效,但是当方法结束时应用程序curshes,并且根本不显示警告对话框!!!

请帮忙!

【问题讨论】:

    标签: android android-fragments android-webview android-dialog android-dialogfragment


    【解决方案1】:

    showErrorDialog() 也应该有 @JavascriptInterface 如果它是从 webview 的 JavaScript 访问的方法。你没有告诉我们什么 rerror 打印 logcat。

    【讨论】:

    • 我添加了,但还是不行,是不是webinterface上下文不能传递给dialogFragment?,你还有什么建议吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-19
    • 2012-06-09
    • 1970-01-01
    • 2013-06-14
    • 2019-09-25
    相关资源
    最近更新 更多