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