0
활동 내에 사용자 정의 대화 상자를 표시하려고하는데이 오류가 발생합니다. 나는이 오류가 here과 here에서 발생하는 이유를 알고 있으며 또한 해결책을 알고 있습니다. 하지만 문제는 내 코드에서 문제를 찾을 수 없다는 것입니다. 나는 행운이없는 오류를 찾는 데 시간을 할애했다. 가 나는 Activity
살아야하는 동안 여기에 대화 상자를 표시하고활동이 윈도우를 유출했습니다 - 사용자 정의 대화 상자
public void changePassword(View view){
DialogChangePassword dialogChangePassword = new DialogChangePassword(ActivityMyAccount.this);
dialogChangePassword.show();
Window window = dialogChangePassword.getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
버튼을 클릭에 방법 아래라고했습니다. 내 질문;
- 여기 대화 상자를 닫을 수 없으므로
Dialog
클래스에서 해당 대화 상자를 닫습니다. - 나는 활동을 마무리하지 않을 것입니다. 활동이 완료되어 오류가 발생하면 왜 완료됩니까?
- 활동을 완료하여 오류가 발생하지 않은 경우이 오류가 발생하는 이유는 무엇입니까?
- Dialog 클래스에서 수행해야 할
NetworkOperation
이 있는데,이 작업을 수행해야합니까? 여기
내 대화 상자 클래스
public class DialogChangePassword extends Dialog {
Context context;
Button confirm, cancel;
CustomEditText edtOldPwd, edtNewPwd, edtConfirmNewPwd;
ProgressDialog progressDialog;
String PASSWORD_INCORRECT_MESSAGE = "Old password is incorrect.";
public DialogChangePassword(Context context) {
super(context);
this.context = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialog_change_password);
if(progressDialog != null)
progressDialog = null;
progressDialog = new ProgressDialog(context);
progressDialog.setTitle("Please wait...");
progressDialog.setMessage("Updating Password.");
progressDialog.show();
confirm = (Button) findViewById(R.id.btnChangePassword);
cancel = (Button) findViewById(R.id.btnCancel);
edtOldPwd = (CustomEditText) findViewById(R.id.edtOldPassword);
edtNewPwd = (CustomEditText) findViewById(R.id.edtNewPassword);
edtConfirmNewPwd = (CustomEditText) findViewById(R.id.edtConfirmNewPassword);
edtConfirmNewPwd.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (!edtNewPwd.getText().toString().equals(edtConfirmNewPwd.getText().toString()))
edtConfirmNewPwd.setError("Password doesn't match");
}
});
confirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!edtNewPwd.getText().toString().equals(edtConfirmNewPwd.getText().toString())) {
Toast.makeText(context, "Password doesn't match", Toast.LENGTH_SHORT).show();
progressDialog.cancel();
return;
}
HashMap<String, String> params = new HashMap<>();
params.put("email", Utility.classUser.getEmailId());
params.put("password", edtOldPwd.getText().toString());
params.put("newPassword", edtNewPwd.getText().toString());
new NetworkOperation().execute(params);
}
});
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
}
private class NetworkOperation extends AsyncTask<HashMap<String,String>, Void, String> {
@Override
protected String doInBackground(HashMap<String, String>... params) {
try {
ClassAPIRoutes routes = ClassAPIRoutes.initializeRoutes();
return routes.editUserPassword(params[0]);
} catch (final IOException e) {
e.printStackTrace();
getOwnerActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(context, e.toString(), Toast.LENGTH_SHORT).show();
}
});
return "error";
}
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
progressDialog.cancel();
dismiss();
if(!s.equals("error")){
JSONObject jsonObject;
try {
jsonObject = new JSONObject(s);
if (jsonObject.get("success").toString().equals("true")) {
Toast.makeText(context, "Password successfully changed.", Toast.LENGTH_SHORT).show();
dismiss();
} else if (jsonObject.get("success").toString().equals("false")) {
if (jsonObject.get("message").toString().equals(PASSWORD_INCORRECT_MESSAGE)) {
Toast.makeText(context, PASSWORD_INCORRECT_MESSAGE, Toast.LENGTH_SHORT).show();
resetFields();
}
}
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getContext(), s, Toast.LENGTH_SHORT).show();
}
}
}
}
private void resetFields(){
edtOldPwd.setText("");
edtNewPwd.setText("");
edtConfirmNewPwd.setText("");
}
}
이 대화 상자/진행 대화 상자/경고를 기각 잘 작동하고 삭제했습니다입니다 당신의 활동을 끝내기 전에 대화 상자를 열면 누출이 없을 것입니다 : – SripadRaj
당신의 대화는 당신의 활동의 문맥을 유지합니다. @SripadRaj가 말했듯이, 활동을 끝내기 전에 대화를 닫고 onStop에 넣을 수도 있습니다. – gitter
@gitter 비밀번호를 변경 한 후 다시 활동으로 돌아가고 싶습니다. 활동이 마무리되는 이유는 무엇입니까? 만약 그렇다면'DialogChangePassword'가 사라지고 암호를 변경할 수 없게됩니다. 글쎄, 나는 운이없는 시도했다 –