views:

160

answers:

2

I have an EditText field for the user to enter their weight in lbs. How can I override the traditional keyboard and display the numeric keypad instead?

A: 

This is what i pulled off of the google API

//Set the input style to numbers, rather than qwerty keyboard style.
txtView.setInputMethod(DigitsInputMethod.getInstance());
mtmurdock
+1  A: 

This didn't work for me. However, I was able to accomplish the aforementioned by either of the following lines:

// TYPE_CLASS_NUMBER: Class for numeric text. This displays the numbers/symbols keyboard.
editText.setInputType(TYPE_CLASS_NUMBER);

// TYPE_CLASS_PHONE: Class for a phone number. This displays the phone number keypad.
editText.setInputType(TYPE_CLASS_PHONE);
wldworld