Nayana Bhoj Nayana Bhoj - 22 days ago 7
Android Question

How to capitalize first letter of edit text in android

I tried following things still not working:

android:inputType="textCapSentences"
android:capitalize="sentences"

Answer

Check these solution:

edittext.addTextChangedListener(new TextWatcher() {

    @Override
    public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {            

    }
        @Override
    public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                    int arg3) {             
    }
    @Override
    public void afterTextChanged(Editable et) {
          String s=et.toString();
      if((!s.equals(s.toUpperCase()) && s.length()==1)) {
         s=s.toUpperCase();
         edittext.setText(s);
      }
    }
});