栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

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

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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();
    }

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/340983.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号