我正在尝试在编辑按钮中添加登录功能。我想要实现的是,当用户选择一个项目进行编辑,然后点击编辑按钮时,会弹出一个窗口询问该人的用户名和密码。我尝试创建了一个登录对话框,但总是失败。
这是我的代码:
当我点击“确认”按钮时,它会显示“用户名或密码不正确”的消息。但是我已经输入了正确的用户名和密码。有什么帮助吗?
这是我的代码:
public void btn_edit_click(View v){
LayoutInflater li = LayoutInflater.from(context);
View prompt = li.inflate(R.layout.prompts, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setView(prompt);
final String username = getIntent().getStringExtra("USERNAME");
final EditText user = (EditText) prompt.findViewById(R.id.loginEmail);
final EditText pass = (EditText) prompt.findViewById(R.id.loginPassword);
final TextView msg = (TextView) prompt.findViewById(R.id.login_error);
final String password = pass.getText().toString();
user.setText(getIntent().getStringExtra("USERNAME"));
if(this.selected_website != null){
alertDialogBuilder.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
DBAdapter dbUser = new DBAdapter(PasswordActivity.this);
dbUser.open();
if(dbUser.Login(username, password))
{
show_add_layout();
}
else
{
msg.setText("Username or Password is incorrect");
}
}
});
alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
alertDialogBuilder.show();
}
else{
show_mesg("Please select item to edit.");
}
}
当我点击“确认”按钮时,它会显示“用户名或密码不正确”的消息。但是我已经输入了正确的用户名和密码。有什么帮助吗?