Search code examples
androidtextview

InputType = PersonName?


I have a TextView object that's purpose is to type in the name of a person. I looked at here and saw that textPersonName is an input type. So I selected that input type, thinking that it would do what I wanted.

However, this input type does not capitalize the first letter. As people's names start with capital letters, I found this to be very odd. Is this intentional, or a design oversight on Google's part?

In any case, I have selected textCapWords as the new input type to make sure every word starts capitalized. Will there be any disadvantage to using this input type for a person's name? What are the benefits of using textPersonName as the input type?


Solution

  • You can combine the inputType attributes using an | (or) operator.

    http://developer.android.com/reference/android/widget/TextView.html#attr_android:inputType

    The type of data being placed in a text field, used to help an input method decide how to let the user enter text. The constants here correspond to those defined by InputType. Generally you can select a single value, though some can be combined together as indicated. Setting this attribute to anything besides none also implies that the text is editable.

    Must be one or more (separated by '|') of the following constant values.

    So to combine the benefits of textPersonName with textCapWords, simply set the input type using this syntax:

    android:inputType="textPersonName|textCapWords"
    

    This answer gives a brief explanation of the benefits of using textPersonName for a name entry field.