2016-08-12 57 views
0

後改變其狀態,我有一個問題,當我輸入我不想鍵盤的文本自動改變,但空間鍵盤改變到原來的狀態了。
例如,我想撥打我進入這個狀態下,鍵盤的數字:enter image description here

但是,當我需要輸入後面加一個空格的數量,鍵盤本身會自動更改:enter image description here

它是必要時用戶自己可以改變鍵盤的狀態,如果需要輸入字符的話。我在編輯文本的文本上使用了一個蒙版。藉助這個庫設置掩碼:MaskFormatter。一個面具的例子:
private static final String MASK = "99 AA 999999"; private EditText mInputCertificate; @Override public void setViews(View rootView, Bundle savedInstanceState) { // Some code mInputCertificate = (EditText) rootView.findViewById(R.id.input_car_certificate); MaskFormatter maskFormatter = new MaskFormatter(MASK, mInputCertificate); mInputCertificate.addTextChangedListener(maskFormatter); }

有辦法解決這個問題嗎?鍵盤空格

+0

您爲EditText添加了inputType? – Esperanz0

+0

在xml文件中沒有設置此選項,並且我下載並構建了類似java類的應用程序的庫,它刪除了類CharInputType中的替換鍵盤。 – metalink

回答

0

我做了我的自定義TextWatcher爲EditText上:

private String getString (String s) { 
    String newValue = s.replaceAll("\\s", ""); 
    /*if (newValue.length() < 2 || newValue.length() >= 4) { 
     mEditText.setInputType(InputType.TYPE_CLASS_NUMBER); 
    } else { 
     mEditText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); 
    }*/ 
    StringBuilder builder = new StringBuilder(); 
    for (int i =0; i < newValue.length(); i++) { 
     if (i == 2 || i == 4) { 
      builder.append(' '); 
      builder.append(newValue.charAt(i)); 
     } else { 
      builder.append(newValue.charAt(i)); 
     } 
    } 
    return builder.toString(); 
} 

@Override 
public void afterTextChanged(Editable s) { 
    Log.d("EDITTEXT", "getEditable " + s); 
    String text = getString(s.toString()); 
    mEditText.removeTextChangedListener(this); 
    mEditText.getText().clear(); 
    mEditText.append(text.toUpperCase()); 
    mEditText.addTextChangedListener(this); 
    mEditText.setSelection(mEditText.length()); 
} 

這爲我工作。我用.append(SomeText)代替.setText(SomeText)。