Vorlesungen
  Download     DBS     Sprachen     Oberflächen     Impressum     Datenschutz  
1. Sem
2. Sem
3. Sem
4. Sem
5. Sem
Android
iOS
Webprogrammierung
Web-Technologien
Wahlpflicht-SoSe
Wahlpflicht-WiSe
IEA-2019
Projektwochen
Allgemein:
Startseite
Vorlesungen
Labore
Sinnvolle Programme
Lineare Regression
GUI-Entwurfsarbeit
Single-Format
Design Pattern-Termine
Observer1
Bsp2
Json-Array
Json-Dialogelemente
Webtechnologien

EditText-onChange-events

simple sample

edtext.addTextChangedListener(new TextWatcher() {

   @Override
   public void onTextChanged(CharSequence s, int start, int before, int count) {
   }

   @Override
   public void beforeTextChanged(CharSequence s, int start, int count, int after) {
   }

   @Override
   public void afterTextChanged(Editable s) {
      // setEnable or disabled for ok-button
   }
});

simple sample


complete sample

private Pattern namePattern = Pattern.compile("^([A-Z][a-z]{1,29})[,][ ]([A-Z][a-z]{1,29})$");
private boolean isNameOk=true;


private void setEnabledbnOk() {
    bnSaveChanges.setEnabled(this.isNameOk);
}

// in onCreate
edtext.addTextChangedListener(new TextWatcher() {
   // check, if
   private boolean isValid(CharSequence s) {
       return namePattern.matcher(s).matches();
   }

   @Override
   public void onTextChanged(CharSequence s, int start, int before, int count) {
   }

   @Override
   public void beforeTextChanged(CharSequence s, int start, int count, int after) {
   }

   @Override
   public void afterTextChanged(Editable s) {
      if (isValid(s))  {
          tvValidStdname.setText("");  // a textview which has a blank or a star (*)
          isNameOk = true;
      }
      else {
          tvValidStdname.setText("*");
          isNameOk=false;
      }
      setEnabledbnOk();
   }
});

EditText
EditText readonly