Code example for EditText

Methods: lengthsetText, setVisibility

0
        // Hack for pre-3.0 Android: can enter text into disabled EditText. 
        if (!isChecked) { // Clear server input.
          serverInput.setVisibility(View.GONE);
          serverInput.setText("");
        } else { 
          serverInput.setVisibility(View.VISIBLE);
        } 
        // Activate connectButton if necessary. 
        activateView(connectButton, validateInputs());
      } 
    }); 
  } 
 
  @Override 
  public void onStart() { 
    super.onStart(); 
    // Start with an empty form 
    usernameInput.setText("");
    passwordInput.setText("");
    synckeyInput.setText("");
    passwordInput.setText("");
  } 
 
  public void cancelClickHandler(View target) {
    finish();
  } 
 
  /* 
   * Get credentials on "Connect" and write to AccountManager, where it can be 
   * accessed by Fennec and Sync Service. 
   */ 
  public void connectClickHandler(View target) {
    Log.d(LOG_TAG, "connectClickHandler for view " + target);
    username = usernameInput.getText().toString();
    password = passwordInput.getText().toString();
    key = synckeyInput.getText().toString();
    if (serverCheckbox.isChecked()) {
      server = serverInput.getText().toString();
    } 
    enableCredEntry(false); 
 
    // TODO : Authenticate with Sync Service, once implemented, with 
    // onAuthSuccess as callback 
 
    authCallback(); 
  } 
 
  /* Helper UI functions */ 
  private void enableCredEntry(boolean toEnable) {
    usernameInput.setEnabled(toEnable);
    passwordInput.setEnabled(toEnable);
    synckeyInput.setEnabled(toEnable);
    if (!toEnable) {
      serverInput.setEnabled(toEnable);
    } else { 
      serverInput.setEnabled(serverCheckbox.isChecked());
    } 
  } 
 
  private TextWatcher makeInputValidator() {
    return new TextWatcher() {
 
      @Override 
      public void afterTextChanged(Editable s) {
        activateView(connectButton, validateInputs());
      } 
 
      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count,
          int after) {
      } 
 
      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) {
      } 
    }; 
  } 
 
  private boolean validateInputs() { 
    if (usernameInput.length() == 0 || passwordInput.length() == 0
        || synckeyInput.length() == 0
        || (serverCheckbox.isChecked() && serverInput.length() == 0)) {
      return false; 
    } 
    return true; 
  }