Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an array of editTexts which I make like this:

        inputs[i] = new EditText(this);
        inputs[i].setWidth(376);
        inputs[i].setInputType(InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
        tFields.addView(inputs[i]);

I want every character to be capitalized. Right now, the first letter of the first word is lowercase, then all the characters afterwords are upper case. I can take what the user inputs after they are done and convert that to uppercase, but that's not really what I'm going for. Is there a way to get these fields to behave the way I want them to?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
393 views
Welcome To Ask or Share your Answers For Others

1 Answer

You need to tell it it's from the "class" text as well:

inputs[i] = new EditText(this);
inputs[i].setWidth(376);
inputs[i].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
tFields.addView(inputs[i]);

The input type is a bitmask. You can combine the flags by putting the | (pipe) character in the middle, which stands for the OR logic function, even though when used in a bitmask like this it means "this flag AND that other flag".

(This answer is the same as Robin's but without "magic numbers", one of the worst things you can put in your code. The Android API has constants, use them instead of copying the values and risking to eventually break the code.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...