关闭AlertDialog.Builder

时间:2018-09-05 15:37:25

标签: android alertdialog dismiss

在我的代码中,我试图进行AlertDialog登录,但是一旦按下按钮就无法关闭它,有人知道吗?我尝试从构建器创建AlertDialog对象,但是它不起作用。这是我的代码:

|

2 个答案:

答案 0 :(得分:0)

您应该致电builder.create()而不是致电builder.show()。它会向您返回一个对话框实例,然后将可以调用show()dismiss()方法。

答案 1 :(得分:0)

您的函数应如下所示:

model.add(LSTM(10, return_sequences = False, input_shape = (8, 8)))

然后您可以像这样调用它:

public AlertDialog createSigninDialog (){

        final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

        LayoutInflater inflater = MainActivity.this.getLayoutInflater();

        View view = inflater.inflate(R.layout.dialog_signin, null);

        builder.setView(view);

        final AlertDialog dialog = builder.create();

        signin = (Button)view.findViewById(R.id.singing);
        user = (EditText)view.findViewById(R.id.user_input);
        password = (EditText)view.findViewById(R.id.password_input);


        signin.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (user.getText().toString().equals("1234567890") && password.getText().toString().equals("1234")){
                            Toast.makeText(MainActivity.this, "Login", Toast.LENGTH_SHORT).show();
                            //Dismiss here
                            dialog.dismiss();
                        } else {
                            Toast.makeText(MainActivity.this, "Datos incorrectos", Toast.LENGTH_SHORT).show();
                            //Dismiss here
                            dialog.dismiss();
                        }
                    }
                }
        );

        return dialog;
    }