Skip to content

Instantly share code, notes, and snippets.

@codevscolor
Created February 11, 2016 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codevscolor/4a1a13d1a88b72be0e4c to your computer and use it in GitHub Desktop.
Save codevscolor/4a1a13d1a88b72be0e4c to your computer and use it in GitHub Desktop.
public class MainActivity extends AppCompatActivity {
private EditText etEmail;
private EditText etPassword;
private Button loginButton;
private String emailText;
private String pwdText;
private TextInputLayout emailLayout;
private TextInputLayout pwdLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etEmail = (EditText) findViewById(R.id.editTextEmail);
etPassword = (EditText) findViewById(R.id.editTextPassword);
loginButton = (Button) findViewById(R.id.button);
emailLayout = (TextInputLayout) findViewById(R.id.layout_email);
pwdLayout = (TextInputLayout) findViewById(R.id.layout_password);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
login();
}
});
}
private void login() {
emailText = etEmail.getText().toString().trim();
pwdText = etPassword.getText().toString().trim();
if (emailText.isEmpty()) {
emailLayout.setError(getString(R.string.hint_empty));
} else if (!android.util.Patterns.EMAIL_ADDRESS.matcher(emailText).matches()) {
emailLayout.setError(getString(R.string.error_email));
} else {
emailLayout.setErrorEnabled(false);
}
if (pwdText.isEmpty()) {
pwdLayout.setError(getString(R.string.hint_empty));
} else {
pwdLayout.setErrorEnabled(false);
}
if (!emailLayout.isErrorEnabled() && !pwdLayout.isErrorEnabled()) {
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DialogStyle);
builder.setMessage("Successfull !!");
builder.setPositiveButton("OK", null);
builder.show();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment