【问题标题】:AlertDialog not showing, and no error messageAlertDialog 未显示,也没有错误消息
【发布时间】:2013-02-27 04:47:35
【问题描述】:

我的AlertDialog 有什么问题? Logcat 仅到达 "after builder set items",然后它停止并且没有错误消息。应用程序的其余部分继续没有问题。不知道为什么AlertDialog 不会显示。

AlertDialog.Builder builder = new AlertDialog.Builder(this.cordova.getActivity());
Log.d(LOG_TAG, "after new AlertDialog");
builder.setTitle(title);
Log.d(LOG_TAG, "after builder set title");
CharSequence[] choicesAsCharSeq = choices.toArray(new CharSequence[choices.size()]);
builder.setItems(choicesAsCharSeq, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
        // The 'which' argument contains the index position
        // of the selected item
        Log.d(LOG_TAG, "Index #" + which + " chosen.");
        String result = "";
        result = "" + which;
        // ActionSheet.this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
    }
});
Log.d(LOG_TAG, "after builder set items");
builder.show();
Log.d(LOG_TAG, "after builder show");

【问题讨论】:

  • 您在标签中提到了 logcat。那么,logcat 在哪里呢?
  • 可能你从 appwidget 或非 UI 线程调用对话框。
  • 我想这个问题与 logcat 本身无关。
  • @AlexKucherenko 你可能是对的。这是在phonegap中。我正在使用这一行来声明我的班级:public class ActionSheet extends Plugin {
  • 但如果我使用new AlertDialog.Builder(this.cordova.getActivity()),它应该在主线程上吗?

标签: java android cordova android-alertdialog phonegap-plugins


【解决方案1】:

我将插件更改为扩展 CordovaPlugin 而不是 Plugin,问题就消失了。

【讨论】:

    【解决方案2】:

    你必须写

    builder.create().show();
    

    而不是

    builder.show();
    

    【讨论】:

    • Show 将自动创建对话框,如果它还没有完成。
    猜你喜欢
    • 2020-11-12
    • 1970-01-01
    • 2020-09-25
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多