33

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?

Mike Baxter
  • 6,868
  • 17
  • 67
  • 115
  • I haven't played around with textPersonName myself. But some names don't always have a capital. I guess stuff like von, af etc. (European). As for the benefits, no idea. – David Olsson Jul 02 '13 at 12:03
  • 1
    I think capitalized by default is best as it seems far more likely that someone will want to put in a capitalized name. – Mike Baxter Jul 02 '13 at 12:07
  • 2
    Phantom down-voters; please give constructive criticism. If you give me feedback on my question then I can improve it. At least explain why you think this question does not conform to stack overflow's standards. – Mike Baxter Jul 02 '13 at 12:09
  • 2
    `textPersonName` also does not stop user type in numbers or other characters which cannot appear in a person's name. To enable user to put only valid chars, using `android:digits="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"` helped. – Shubham A. Jul 29 '15 at 05:16

5 Answers5

41

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.

Community
  • 1
  • 1
arbitrarily
  • 534
  • 5
  • 3
13

inputype attribute in EditText widget: (tested on Android 4.4.3 and 2.3.3)

<EditText android:id="@+id/et_test" android:inputType="?????"/>
  • inputType: textLongMessage. Keyboard: alphabet/default. Enter button: Send/Next. Has emotion: yes. Case: lowercase. Suggestion: yes. Addition chars: , and . and everything

  • inputType: textFilter. Keyboard: alphabet/default. Enter button: Send/Next. Has emotion: yes. Case: lowercase. Suggestion: no. Addition chars: , and . and everything

  • inputType: textCapWords. Keyboard: alphabet/default. Enter button: Send/Next. Has emotion: yes. Case: Camel Case. Suggestion: yes. Addition chars: , and . and everything

  • inputType: textCapSentences. Keyboard: alphabet/default. Enter button: Send/Next. Has emotion: yes. Case: Sentence case. Suggestion: yes. Addition chars: , and . and everything

  • inputType: time. Keyboard: numeric. Enter button: Send/Next. Has emotion: no. Suggestion: no. Addition chars: :

  • inputType: textMultiLine. Keyboard: alphabet/default. Enter button: nextline. Has emotion: yes. Case: lowercase. Suggestion: yes. Addition chars: , and . and everything

  • inputType: number. Keyboard: numeric. Enter button: Send/Next. Has emotion: no. Suggestion: no. Addition chars: nothing

  • inputType: textEmailAddress. Keyboard: alphabet/default. Enter button: Send/Next. Has emotion: no. Case: lowercase. Suggestion: no. Addition chars: @ and . and everything

  • inputType: (No type). Keyboard: alphabet/default. Enter button: nextline. Has emotion: yes. Case: lowercase. Suggestion: yes. Addition chars: , and . and everything

  • inputType: textPassword. Keyboard: alphabet/default. Enter button: Send/Next. Has emotion: no. Case: lowercase. Suggestion: no. Addition chars: , and . and everything

  • inputType: text. Keyboard: Keyboard: alphabet/default. Enter button: Send/Next. Has emotion: yes. Case: lowercase. Suggestion: yes. Addition chars: , and . and everything

  • inputType: textShortMessage. Keyboard: alphabet/default. Enter button: emotion. Has emotion: yes. Case: lowercase. Suggestion: yes. Addition chars: , and . and everything

  • inputType: textUri. Keyboard: alphabet/default. Enter button: Send/Next. Has emotion: no. Case: lowercase. Suggestion: no. Addition chars: / and . and everything

  • inputType: textCapCharacters. Keyboard: alphabet/default. Enter button: Send/Next. Has emotion: yes. Case: UPPERCASE. Suggestion: yes. Addition chars: , and . and everything

  • inputType: phone. Keyboard: numeric. Enter button: Send/Next. Has emotion: no. Suggestion: no. Addition chars: *** # . - / () W P N , +**

  • inputType: textPersonName. Keyboard: alphabet/default. Enter button: Send/Next. Has emotion: yes. Case: lowercase. Suggestion: yes. Addition chars: , and . and everything

Note: Auto-capitalization setting as shown in the following screenshot will change the default behavior (True is default, textCapWords will work as expected. False will override textCapWords)

Auto-capitalization setting

Note 2: In the Numeric keyboard, ALL numbers are English 1234567890.

Note 3: Correction/Suggestion setting overrides the default behavior.

OneWorld
  • 17,512
  • 21
  • 86
  • 136
Yousha Aleayoub
  • 4,532
  • 4
  • 53
  • 64
2

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?

Don't seems to be any problem here as your just changing the input type specifying it as a initial letter to Capital but it will allow multiple lines to be entered.This can be a disadvantage when you want only a single line with a person name.

What are the benefits of using textPersonName as the input type?

Single line entry in the textfield is the advantage for using text input as textPerson.

NetStarter
  • 3,189
  • 7
  • 37
  • 48
  • 1
    Thanks. Is there a way to have single line entry with `textPerson`, but also have the first letter of every word capitalized? (Best of both worlds?) – Mike Baxter Jul 02 '13 at 12:05
  • http://stackoverflow.com/questions/13705776/how-to-capitalize-every-letter-in-an-android-edittext for you `TextWatcher` will be helpful you will need to use it according to your need hope this is helpful – NetStarter Jul 02 '13 at 12:07
  • 2
    @Teifi I think you can combine input types with the `|` operator. – Code-Apprentice Apr 10 '14 at 01:34
1
public class MainActivity extends Activity {

TextView tv1;

EditText et1;

Button bt1; 

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    tv1=(TextView)findViewById(R.id.textView1);

    et1=(EditText)findViewById(R.id.editText1);

    bt1=(Button)findViewById(R.id.button1);


    bt1.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub


    String s=et1.getText().toString();

    //char s1=s.charAt(0);


     if (s.length() <= 1) {
            s = s.toUpperCase();
        } else {
            s = s.substring(0, 1).toUpperCase() +s.substring(1);
        }        

     tv1.setText(s);

}
});

}
Mike Baxter
  • 6,868
  • 17
  • 67
  • 115
ashu
  • 109
  • 5
1

Spelling check is not done when using android:inputType="textPersonName" but it is done in **textCapWords**

So if you use textPersonName there won't be red underline for names but first letter of each name(firstname, middlename, lastname etc) won't be capitalized

so best solution is combining both with an or that is android:inputType="textPersonName|textCapWords"

now there wont be red underline for name and first letter would be capitalized also

Learning Always
  • 1,563
  • 4
  • 29
  • 49
Jilson
  • 569
  • 5
  • 11