gpt4 book ai didi

android - 按肯定按钮为什么对话框关闭?

转载 作者:行者123 更新时间:2023-11-30 04:33:04 26 4
gpt4 key购买 nike

实际上我正在检查我的对话框中的一些值,如果它们无效我不想关闭我的对话框。不幸的是默认情况下当我按下提交按钮时我的对话框被关闭 :( 我怎么能逃脱???

LayoutInflater factory = LayoutInflater.from(EmailJavaAPI.this);
final View textEntryView = factory.inflate(R.layout.usrpwsdialog,null);
((EditText)textEntryView.findViewById(R.id.etxtUserName)).setText((((EditText)findViewById(R.id.editTextFrom)).getText()).toString());

final EditText usrName = (EditText)textEntryView.findViewById(R.id.etxtUserName);
final EditText usrPws = (EditText)textEntryView.findViewById(R.id.etxtPws);

//AlertDialog alert=new AlertDialog(EmailJavaAPI.this);


return new AlertDialog.Builder(EmailJavaAPI.this)
.setTitle(R.string.kpsdomain)
.setView(textEntryView)
.setPositiveButton(R.string.dgbtnsubmit,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
userName = usrName.getText().toString().trim();
userPws = usrPws.getText().toString().trim();
((EditText)findViewById(R.id.editTextFrom)).setText(userName);

if(userName.equals("")){
textEntryView.findViewById(R.id.txtVWRUserName).setVisibility(View.VISIBLE);
}
if(userPws.equals("")){
textEntryView.findViewById(R.id.txtVWRPws).setVisibility(View.VISIBLE);
}
if(!userName.equals("")&& !userPws.equals("")){
Toast.makeText(EmailJavaAPI.this, "User Name and Password has been set up", Toast.LENGTH_SHORT).show();
}
else{
//***IMPORTANT***
//Dialog Should be opened if this condition is true
}
}
})
.setNegativeButton(R.string.dgbtnDiscard,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
dialog.dismiss();
}
}).create();

最佳答案

这是警报对话框的默认行为。您需要像这样自定义它:

@Override
protected Dialog onCreateDialog(int id) {

LayoutInflater inflator = LayoutInflater.from(context);
View view = inflator.inflate(R.layout.yourview, null);
Button positive = (Button)view.findViewById(R.id.btn_positive);
Button negative = (Button)view.findViewById(R.id.btn_negative);

positive.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
removeDialog(0);
}
});

negative.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
removeDialog(0);
}
});

AlertDialog dialog = new AlertDialog.Builder(this).create();
dialog.setView(view);

return dialog;
}

当您调用 removeDialog(0) 时,它将删除对话框。

关于android - 按肯定按钮为什么对话框关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7359719/

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