gpt4 book ai didi

android - 安卓密码提示

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:39:44 26 4
gpt4 key购买 nike

我正在尝试进行密码提示,当用户输入错误的密码时,它会显示一个对话框要求“取消”或“重试”,当用户点击“重试”时,它会再次显示密码提示.

下面是图片来说明我的意思

enter image description here

enter image description here

我是这样做的

 /** 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();

}
});

有人知道怎么做吗?

最佳答案

我已经解决了我自己的问题。我为我的警报对话框创建了一个方法,然后当我单击“重试”时,我将再次调用该方法。 :)

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 - 安卓密码提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12683547/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com