【问题标题】:Dialog Box Close Automatically对话框自动关闭
【发布时间】:2013-07-26 06:12:15
【问题描述】:

我想在我的编码中添加对话框。该对话框能够弹出。假设用户按下确定按钮后对话框将关闭,但对话框自动关闭。这是我的代码。有什么问题吗?

private void updataAccount(int type){
    Iterator<AccountData> iteratorSort = commondata.account.values().iterator();
    while (iteratorSort.hasNext()){
        AccountData data = iteratorSort.next();
        if(data.id == Integer.parseInt(accountId[account_spn.getSelectedItemPosition()]))
        {
            if(type == INCOME_MODE){
                data.balance = data.balance+Double.parseDouble(value);
                commondata.updateAccount(data);
            }else if(type == PAYOUT_MODE){
                data.balance = data.balance-Double.parseDouble(value);
                commondata.updateAccount(data);
                if(data.balance < 0)
                {
                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    builder
                    .setTitle("Care Money")
                    .setMessage("Your amount in this account is negative!")
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .setPositiveButton("OK", new DialogInterface.OnClickListener() 
                    {
                        public void onClick(DialogInterface dialog, int which) 
                        {       
                               dialog.dismiss();
                    }
                    });                     
                AlertDialog alert = builder.create();
                        alert.show();
                }
            }
            return;
        }
    }

【问题讨论】:

  • 当你说自动时,它会在一定的时间或事件之后执行吗?
  • @frogmanx 是的。它会在 1 秒后自动关闭,弹出对话框。
  • 我没有看到任何导致这种情况的原因??
  • 我不认为它会自动关闭。我也试过代码。

标签: android dialog


【解决方案1】:

试试这个

builder.setCancelable(false);
    builder.show();

而不是这个

AlertDialog alert = builder.create();
            alert.show();

【讨论】:

【解决方案2】:

Chitan 请试试这个代码 它对我来说很好,希望它能以某种方式帮助你

AlertDialog.Builder builder = new AlertDialog.Builder(this);
                     builder.setTitle("Error");
                     builder.setMessage(error)
                            .setCancelable(false)
                            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    error="";
                                }
                            });
                     AlertDialog alert = builder.create();
                     alert.show();

【讨论】:

    【解决方案3】:

    创建一个显示对话框的AsyncTask,然后休眠 1000 毫秒,然后关闭对话框。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-02
    • 1970-01-01
    • 2012-11-14
    • 1970-01-01
    • 1970-01-01
    • 2011-09-21
    相关资源
    最近更新 更多