2013-07-10 9 views
0

我使用FormEditText窗口小部件(很明顯)。事情是:經過測試無效一次後,即使輸入正確的輸入並且field.testValidity()返回true,警告紅色感嘆號也不會消失。我也沒有找到手動清除它的方法FormEditText。 其他人都遇到過這個?FormEditText在正確輸入後沒有清除

這是我使用的時候發送按鈕操作欄中拍了拍方法:

public boolean checkFields() { 

    FormEditText[] allFields = { firstname, lastname, street, zip, city, 
      email, phone }; 

    boolean allValid = true; 
    FormEditText firstFailedField = null; 
    for (FormEditText field : allFields) { 
     if (!field.testValidity()) { 

      Log.d("FOR", "failed field: " + field.getHint()); 

      allValid = false; 

      if (firstFailedField == null) { 
       firstFailedField = field; 
      } 
     } 

    } 

    if (allValid) { 

    } else { 
     firstFailedField.requestFocus(); 
    } 

    return allValid; 

} 

這是我的佈局的一部分:

<com.andreabaccega.widget.FormEditText 
      android:id="@+id/firstname" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="8dp" 
      android:ems="10" 
      android:hint="Vorname" 
      android:inputType="textPersonName" 
      android:singleLine="true" 
      whatever:customRegexp="[a-zA-Z]{2,}" 
      whatever:emptyErrorString="Bitte Vornamen angeben" 
      whatever:testErrorString="Bitte Vornamen angeben" 
      whatever:testType="regexp" > 
     </com.andreabaccega.widget.FormEditText> 

     <com.andreabaccega.widget.FormEditText 
      android:id="@+id/lastname" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="8dp" 
      android:ems="10" 
      android:hint="Nachname" 
      android:inputType="textPersonName" 
      android:singleLine="true" 
      whatever:customRegexp="[a-zA-Z]{2,}" 
      whatever:emptyErrorString="Bitte Nachnamen angeben" 
      whatever:testErrorString="Bitte Nachnamen angeben" 
      whatever:testType="regexp" > 
     </com.andreabaccega.widget.FormEditText> 

我的名字字段中輸入金,按下發送。 Theres在姓氏字段上發出警告。在姓氏字段中輸入J​​ong,但感嘆號不會隱藏。並且該字段測試有效!

enter image description here

+0

你可以嘗試field.setError(null):這樣你就可以從EditText中隱藏錯誤。它應該爲FormEditText工作,因爲FormEditText延伸EditText –

+0

這似乎工作,謝謝! – FWeigl

+0

@UngureanuLiviu [我剛剛通過源代碼](https://github.com/vekexasia/android-form-edittext/blob/master/library/src/com/andreabaccega/widget/DefaultEditTextValidator.java#L111)並想現在說同樣的話。但看起來你更快。你應該把它作爲回答:) – Ahmad

回答

2

作爲建議我會後我的評論作爲一個答案:

您可以嘗試field.setError(空):在這種方式,您可以隱藏一個EditText錯誤。它應該爲FormEditText工作,因爲FormEditText擴展了EditText。