In my code, I'm trying to make an AlertDialog login, but I can not close it once the button is pressed, does anyone know any way? I tried creating an AlertDialog object from the builder, but it does not work. This is my code:
public class MainActivity extends AppCompatActivity {
ImageButton login;
Button signin;
EditText user, password;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
login = (ImageButton)findViewById(R.id.login);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
view.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.imagen_click));
createSigninDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
});
}
public AlertDialog createSigninDialog (){
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);
signin = (Button)view.findViewById(R.id.button_ingresar);
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) {
v.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.imagen_click));
if (user.getText().toString().equals("1234567890") && password.getText().toString().equals("1234")){
Toast.makeText(MainActivity.this, "Login", Toast.LENGTH_SHORT).show();
//Dismiss here
} else {
Toast.makeText(MainActivity.this, "Datos incorrectos", Toast.LENGTH_SHORT).show();
//Dismiss here
}
}
}
);
return builder.show();
}
}