I've successfully displayed an EditText
in the AlertDialog
. When entered text in the edit field, it is compared with a custom text. If the entered text doesn't match, the AlertDilaog
should continue to show but currently the dialog is closing Positive Button is clicked, even if a wrong password was entered.
Do you guys have a solution for this?
UPDATED: Here is the code
builder.setView(v)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
EditText enteredPassword = (EditText) v.findViewById(R.id.enteredPassword);
if (enteredPassword.getText().toString().trim().equals(correctPassword.trim()) {
Log.i(TAG, "User Entered Right Answer");
} else {
Log.i(TAG, "User Entered Wrong Answer");
// Continue showing the dialog if Wrong Answer is entered
Toast.makeText(getApplicationContext(), "Enter a proper answer", Toast.LENGTH_LONG).show();
}
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});