Tôi đang cố gắng tạo lời nhắc mật khẩu, khi người dùng nhập sai mật khẩu, nó sẽ hiển thị hộp thoại yêu cầu "hủy" hoặc "thử lại" và khi người dùng nhấp vào "thử lại", nó sẽ hiển thị nhắc lại mật khẩu lần nữa.nhắc mật khẩu trên android
Dưới đây là những hình ảnh để minh họa cho những gì tôi có nghĩa là
Đây là cách tôi đã làm nó
/** RETRIEVE VIEW FROM DIALOGPROMPT.XML AND SET VIEW AS AN ALERTDIALOG BUILDER **/
LayoutInflater li = LayoutInflater.from(context);
View promptsView = li.inflate(R.layout.searchprompt, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setView(promptsView);
final EditText userInput = (EditText) promptsView
.findViewById(R.id.user_input);
// set dialog message
alertDialogBuilder
.setCancelable(false)
.setNegativeButton("Go",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
/** DO THE METHOD HERE WHEN PROCEED IS CLICKED*/
String user_text = (userInput.getText()).toString();
/** CHECK FOR USER'S INPUT **/
if (user_text.equals("oeg"))
{
Log.d(user_text, "HELLO THIS IS THE MESSAGE CAUGHT :)");
Search_Tips(user_text);
}
else{
Log.d(user_text,"string is empty");
String message = "The password you have entered is incorrect." + " \n" + "Please try again";
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Error");
builder.setMessage(message);
builder.setPositiveButton("Cancel", null);
builder.setNegativeButton("Retry", null);
builder.create().show();
}
}
})
.setPositiveButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
});
Có ai biết làm thế nào để làm điều đó?
Giải pháp này là mất tích 'R.layout.searchprompt', 'R.id.user_input' và' Search_Tips()'. –