Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First letter capitalization for EditText

I'm working on a little personal todo list app and so far everything has been working quite well. There is one little quirk I'd like to figure out. Whenever I go to add a new item, I have a Dialog with an EditText view showing inside. When I select the EditText view, the keyboard comes up to enter text, as it should. In most applications, the default seems to be that the shift key is held for the first letter... although it does not do this for my view. There has to be a simple way to fix, but I've searched the reference repeatedly and cannot find it. I'm thinking there has to be an xml attribute for the reference loaded by the Adapter, but I can't find out what it is.

like image 467
Maximus Avatar asked Jan 26 '11 18:01

Maximus


1 Answers

Statically (i.e. in your layout XML file): set android:inputType="textCapSentences" on your EditText.

Programmatically: you have to include InputType.TYPE_CLASS_TEXT in the InputType of the EditText, e.g.

EditText editor = new EditText(this);  editor.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); 

Can be combined with text and its variations to request capitalization of the first character of every sentence.

- Google Docs

like image 157
McStretch Avatar answered Sep 20 '22 04:09

McStretch