【问题标题】:AlertDialog doesn't want to be displayedAlertDialog 不想显示
【发布时间】:2013-03-21 20:28:59
【问题描述】:

当我要求用户删除项目时,我有很好的工作代码。

case R.id.item_Delete:
        Log.d("TAG","Deletion ...");
        AlertDialog.Builder delAllDialog = new AlertDialog.Builder(this);
        delAllDialog.setTitle("Confirm deletion");
        TextView dialogTxt_id = new TextView(this);
        LayoutParams dialogTxt_idLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        dialogTxt_id.setLayoutParams(dialogTxt_idLayoutParams);
        dialogTxt_id.setText("Delete?");
        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.addView(dialogTxt_id); 
        delAllDialog.setView(layout);
        delAllDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
                delete();
            }
        });
        break; 
...

效果很好! 我只是复制这段代码并将其放置在同一菜单代码中的另一个类似活动中。 我的日志中有Deletion..,然后什么也没发生。 LogCat 很清楚,没有错误。

我搜索并找到了其他几个相同的问题(例如 Android - AlertDialog doesn't show when called from Main-Method ),但是清理项目或其他事情都不能解决我的问题.. 有什么想法吗?

【问题讨论】:

  • 您发布的代码中没有 delAllDialog.show() 。这可能是问题

标签: android android-alertdialog


【解决方案1】:

你需要打电话

 delAllDialog.show();

【讨论】:

    【解决方案2】:

    您需要致电delAllDialog.show() 以显示您的警报对话框。

    【讨论】:

      【解决方案3】:

      @Foenix,尝试用YourActivityName.this 替换this

      例如

      AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(SampleActivity.this);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-07-27
        • 1970-01-01
        • 1970-01-01
        • 2017-01-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多