2016-09-27 50 views
0

我想使用輸入過濾器,我可以防止輸入過濾器,並且我的編輯文本的最大長度限制爲200個字符。設置輸入過濾器的空白區域和最大長度

到目前爲止,我有這樣的: 熱到我把最大長度在同一個過濾器

private void setInputFilterForEmailAndPwd(final EditText amountEditText) { 
 
\t InputFilter filter = new InputFilter() { 
 
\t  public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { 
 
\t \t for (int i = start; i < end; i++) { 
 
\t \t  if (Character.isSpace(source.charAt(i))) { 
 
\t \t \t return ""; 
 
\t \t  } 
 
\t \t } 
 
\t \t 
 
\t \t return null; 
 
\t  } 
 
\t }; 
 

 
\t amountEditText.setFilters(new InputFilter[] { filter }); 
 
    } 
 

 

 

 
setInputFilterForEmailAndPwd(emailEdit);

+1

嘗試此。 –

+0

我試過了,它不適用於我 – Katherina

+1

請嘗試以下代碼片段: - InputFilter [] filters = new InputFilter [] {new InputFilter.LengthFilter(200),myFirstSpaceFilter}; // myFirstSpaceFilter是您已創建的過濾器 amountEditText.setFilters(filters); –

回答

0

我找到了解決辦法 我提出了新的輸入濾波器,而不是setInputFilterForEmailAndPwd:

InputFilter filter = new InputFilter() { 
 
\t  public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { 
 
\t \t for (int i = start; i < end; i++) { 
 
\t \t  if (Character.isWhitespace(source.charAt(i))) { 
 
\t \t \t return ""; 
 
\t \t  } 
 
\t \t } 
 
\t \t return null; 
 
\t  } 
 
\t };

然後:

\t emailEdit.setFilters(new InputFilter[] { filter, new InputFilter.LengthFilter(200) });