Reputation: 2233
I have a custom EditText that I use for input of a sequence of digits. I set DigitsKeyListener (getInputType() = 2) on it in the class's constructor.
This does the "right thing" on a Galaxy S (4.0). The keyboard that comes up when the view gains focus only has numbers, "space", period, comma, dash, backspace and "done".
However, on an older 2.2 device, the keyboard that comes up has letters and a much wider range of symbols, none of which I need.
I found an example online that suggested:
setRawInputType(Configuration.KEYBOARD_12KEY);
at the end of initialization. That value is "3". When I do this, the situation is reversed for the two phones. The keyboard on the Galaxy S now has letters (next to each number, like on a phone) whereas the keyboard on the 2.2 device is what I want (i.e. basically a calculator).
Is there a single unified way to get a "calculator" keyboard that works across versions, or is this a situation where I need to do one thing for SDK versions <= X and another for versions > X?
If so, what should the value of "X" be? Is this something that changed with a particular major release?
Upvotes: 1
Views: 2763
Reputation: 81349
You should set the inputType
attribute to "number"
, or do the equivalent runtime call.
Upvotes: 5