0

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

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;
        }
    }
4

3 回答 3

1

尝试使用这个

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

而不是这个

AlertDialog alert = builder.create();
            alert.show();
于 2013-07-26T05:25:21.540 回答
0

Create an AsyncTask that displays the dialog, then sleeps for 1000 milliseconds, then closes the dialog.

于 2013-07-26T05:52:06.333 回答
0

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();
于 2013-07-26T05:39:46.883 回答