Android AlterDialog 点按钮不关闭对话框,自定义AlterDialog

通过AlertDialog 弹出对话框进行密码修改,密码正确之后才关闭对话框

public void modifyPwd(View v) {
        final SharedPreferences sharedPreferences = getBaseContext().getSharedPreferences(GlobalVar.SHARE_PREFERENCE, 0);
        final AlertDialog.Builder normalDialog =
                new AlertDialog.Builder(BusLogActivity.this);
        //normalDialog.setIcon(R.drawable.icon_dialog);
        final View dialogView = LayoutInflater.from(BusLogActivity.this)
                .inflate(R.layout.bus_log_change_pwd, null);
        normalDialog.setTitle("修改密码");
        normalDialog.setView(dialogView);
        normalDialog.setPositiveButton("是",
                null);
        normalDialog.setNegativeButton("否",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //dismissDialog(which);
                    }
                });
        normalDialog.setCancelable(false);
        //normalDialog.show();
        final AlertDialog dialog=normalDialog.create();
        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialogInterface) {
                Button btnPositive = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
                btnPositive.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        EditText pwd_old_et =
                                dialogView.findViewById(R.id.pwd_old_et);
                        EditText pwd_new_et =
                                dialogView.findViewById(R.id.pwd_new_et);
                        String pwd_old = pwd_old_et.getText().toString().trim();
                        String pwd_new = pwd_new_et.getText().toString().trim();
                        if (pwd_old.length() == 0 || pwd_new.length() == 0) {
                            Toast.makeText(getBaseContext(),"请输入密码",Toast.LENGTH_SHORT).show();
                        } else {
                            final String currentPwd = sharedPreferences.getString(GlobalVar.DEFAULT_LOG_NAME, GlobalVar.DEFAULT_LOG_VALUE);
                            if(currentPwd.equals(Util.md5(pwd_old))){
                                sharedPreferences.edit().putString(GlobalVar.DEFAULT_LOG_NAME,Util.md5(pwd_new)).apply();
                                Toast.makeText(getBaseContext(),"密码修改成功",Toast.LENGTH_SHORT).show();
                                dialog.dismiss();
                            }else {
                                Toast.makeText(getBaseContext(),"旧密码不正确",Toast.LENGTH_SHORT).show();
                            }
                        }
                    }
                });
            }
        });
        dialog.show();
        // 显示
       // normalDialog.show();
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值