Skip to content

Instantly share code, notes, and snippets.

@KanshuYokoo
Created August 13, 2018 03:49
Show Gist options
  • Save KanshuYokoo/8a571dd7cec79d8b6369d44e9b95bc9a to your computer and use it in GitHub Desktop.
Save KanshuYokoo/8a571dd7cec79d8b6369d44e9b95bc9a to your computer and use it in GitHub Desktop.
Android, checking if login credentials are filled
public class LoginActivity extends AppCompatActivity implements View.OnClickListener, TextWatcher {
userData user;
private Button mLoginButton;
private EditText mLoginID;
private EditText mLoginPW;
@Override
protected void onCreate(Bundle savedInstanceState) {
mLoginID = findViewById(R.id.loginEdit);
mLoginPW = findViewById(R.id.passwordEdit);
mLoginID.addTextChangedListener(this);
mLoginPW.addTextChangedListener(this);
mLoginButton =(Button)findViewById(R.id.loginButton);
mLoginButton.setEnabled(false);
}
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
mLoginButton.setEnabled(mLoginID.getText().length() > 0 && mLoginPW.getText().length() > 0);
}
@Override
public void afterTextChanged(Editable editable) {
}
@Override
public void onClick(View view) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment