Trong đoạn mã dưới đây, làm cách nào để loại bỏ hộp cảnh báo? Tôi không muốn gây ra rò rỉ bộ nhớ. Tôi đã thử các .dismiss() trên alertDialog, nhưng điều đó không làm việc ... Cảm ơnLàm cách nào để loại bỏ AlertDialog.Builder?
// User pressed the stop button
public void StopMsg_button_action(View view){
final EditText password_input = new EditText(this); // create an text input field
password_input.setHint("Enter Password"); // put a hint in it
password_input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); // change it to password type
AlertDialog.Builder alertDialog = new Builder(this); // create an alert box
alertDialog.setTitle("Enter Password"); // set the title
alertDialog.setView(password_input); // insert the password text field in the alert box
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { // define the 'OK' button
public void onClick(DialogInterface dialog, int which) {
String entered_password = password_input.getText().toString();
if (entered_password.equals(my_password)) {
locManager.removeUpdates(locListener); // stop listening for GPS coordinates
startActivity(new Intent(Emergency_1Activity.this,Main_MenuActivity.class)); // go to main menu
} else {
alert("Incorrect Password");
}
}
});
alertDialog.setNeutralButton("Cancel", new DialogInterface.OnClickListener() { // define the 'Cancel' button
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show(); // show the alert box
}
bạn có thể chỉ cho tôi mã không? Tôi thực sự bối rối ở đây, cảm ơn – sneaky
chắc chắn, hãy xem bản chỉnh sửa của tôi. – FoamyGuy
'AlertDialog.Builder' không có phương thức' hủy' – xmen