Android上的密码提示 [英] password prompt on android
本文介绍了Android上的密码提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试输入密码提示,当用户输入错误的密码时,它将显示一个对话框,要求取消"或重试",当用户单击重试"时,它将再次显示密码提示.
I am trying to make a password prompt, when user entered a wrong password, it will show a dialog asking to "cancel" or "retry" and when the user clicks on "retry", it will display the password prompt again.
下面是说明我的意思的图像
Below are images to illustrate what I meant
这就是我的做法
/** 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();
}
});
有人知道怎么做吗?
推荐答案
我已经解决了自己的问题.我为警报对话框制作了一个方法,然后当我单击重试"时,我将再次调用该方法. :)
I have solved my own problem. I made a method for my alert dialog and then when I click on "retry", i will call the method again. :)
public void showDialog()
{
LayoutInflater li = LayoutInflater.from(context);
View promptsView = li.inflate(R.layout.searchprompt, null);
final 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 \n" + "Please try again!";
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Error");
builder.setMessage(message);
builder.setPositiveButton("Cancel", null);
builder.setNegativeButton("Retry", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
showDialog();
}
});
builder.create().show();
}
}
})
.setPositiveButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.dismiss();
}
}
);
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
这篇关于Android上的密码提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文