gpt4 book ai didi

java - 单击按钮时关闭警报对话框

转载 作者:行者123 更新时间:2023-12-01 19:56:19 25 4
gpt4 key购买 nike

在此alertdialog我让用户输入他们的详细信息,然后将其存储在 Firebase 上。当用户单击 mBookingbtn 时,我该怎么做?它会关闭警报对话框吗?

我主要是想让Negative Close Button的功能在数据保存到数据库时自动运行

这是代码:

final AlertDialog.Builder mBuilder = new AlertDialog.Builder(ProfileActivity.this);
View mView = getLayoutInflater().inflate(R.layout.welcomemessage, null);
final EditText mPlayer1 = (EditText) mView.findViewById(R.id.namepopup);
final EditText mPlayer2 = (EditText) mView.findViewById(R.id.handicappopup);
final EditText mPlayer3 = (EditText) mView.findViewById(R.id.agepopup);
final EditText mPlayer4 = (EditText) mView.findViewById(R.id.genderpopup);
final Button mBookingbtn = (Button) mView.findViewById(R.id.savepopup);
mBookingbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String player1 = mPlayer1.getText().toString().trim();
String player2 = mPlayer2.getText().toString().trim();
String player4 = mPlayer4.getText().toString().trim();
String player3 = mPlayer3.getText().toString().trim();
if (player1.isEmpty()) {
mPlayer1.setError("Please enter player 1");
mPlayer1.requestFocus();
return;
}
if (player2.isEmpty()) {
mPlayer2.setError("Please enter player 2");
mPlayer2.requestFocus();
return;
}
if (player3.isEmpty()) {
mPlayer3.setError("Please enter player 2");
mPlayer3.requestFocus();
return;
}
if (player4.isEmpty()) {
mPlayer4.setError("Please enter player 2");
mPlayer4.requestFocus();
return;
}
String playerone = mPlayer1.getText().toString();
String playertwo = mPlayer2.getText().toString();
String playerthree = mPlayer3.getText().toString();
String playerfour = mPlayer4.getText().toString();
DatabaseReference current_user_db = FirebaseDatabase.getInstance().getReference().child("Users").child(userid);
Map newPost = new HashMap();
newPost.put("name", playerone);
newPost.put("handicap", playertwo);
newPost.put("age", playerthree);
newPost.put("gender", playerfour);
current_user_db.setValue(newPost);
Toast.makeText(ProfileActivity.this, "Details Saved", Toast.LENGTH_SHORT).show();
}


});
mBuilder.setNeutralButton("Close ", new DialogInterface.OnClickListener() { // define the 'Cancel' button
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
mBuilder.setView(mView);
AlertDialog dialog = mBuilder.create();
dialog.show();
}

}

最佳答案

dialog.dismiss();

上面一行用于关闭对话框。将其添加到mBookingButton点击 block 的代码中。

关于java - 单击按钮时关闭警报对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49628960/

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