2017-12-18 4 views
-4

Edittext의 모든 단어는 대문자로 시작해야합니다. 사용자가 소문자 (단어의 첫 글자)로 쓰면 대문자로 변환해야합니다.강제로 각 단어를 Editext의 Capital으로 시작합니다. 사용자는이를 변경하면 안됩니다.

지금까지 아래로 레이아웃을 수행 한

:

<EditText 
     android:id="@+id/edGymName"          
     style="@style/LoginRegisterEditText" 
     android:layout_marginTop="@dimen/size_10" 
     android:layout_toLeftOf="@+id/txtStatusGymStatus" 
     android:hint="@string/gym_tag"       
     android:inputType="textPersonName|textCapWords|textNoSuggestions" 
     android:maxLength="30" /> 

, 나는 사용자가 작은 편지에서 단어의 첫 글자를 쓸 수 싶지 않아요. 이것은 작동하지만 사용자는 작은 경우에 단어의 첫 글자를 쓸 수 있습니다. 우리가 강제로 그것을 허용하지 않으면 어떻게 될까?

+0

@Ankita 질문을 자세히 읽고 "FORCEFULLY"라는 단어의 의미를 알아보십시오. 사용자는 각 단어에 대해 첫 번째 문자를 작게해서는 안됩니다. –

+2

TextWatcher를 구현하면 afterTextChanged()의 첫 번째 문자를 대문자로 쓸 수 있습니다 –

답변

0

당신의 XML 파일이을보십시오 : 사용자가 변경을 수행 한 후을 할 수

android:inputType="text|textCapCharacters" 

또 다른 점은 이것이다, 당신의 텍스트를 편집을 다시 작성합니다.

String oldText = ""; //this must be outside the method where the addTextChangedListener on the editText is set. (Preferrably outside the onCreate()) 

editText.addTextChangedListener(new TextWatcher() { 
    @Override 
    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { 

    } 

    @Override 
    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { 

    } 

    @Override 
    public void afterTextChanged(Editable editable) { 
     if (editable.toString().length() > 0 && 
       !editable.toString().equals(oldText)) { 
      oldText = editable.toString(); //prevent infinite loop 
      editText.setText(capitalizeFirstLetterWord(editable.toString())); 
      editText.setSelection(editText.getText().length()); //set the cursor to the end of the editText 
     } 

    } 
}); 
+0

.. 작동하지 않습니다. !!! –

관련 문제