Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText.setInputType vs. setRawInputType

What is the difference between EditText.setInputType and setRawInputType.

I have a field that should allow for all characters, but I have a mode button that switches between numeric and alpha keyboard.

So I want the numeric keyboard when they are "part number" search mode, but alpha keyboard when they are "description" search mode.

Android OS 2.2 or later.

like image 402
LiteWait Avatar asked Mar 29 '12 21:03

LiteWait


1 Answers

setRawInputType() is usually used when you initialize the view, in a constructor of a custom view or in onCreate() method of an activity, etc. It's the same as if you set inputType with the XML attribute android:inputType. For example:

setContentView(R.layout.main);
mEditText = (EditText) findViewById(R.id.edit_text);
mEditText.setRawInputType(InputType.TYPE_CLASS_NUMBER);
...

In your situation to change the mode of the soft keyboard that is shown for the editor on the fly you have to call setInputType() which also takes care of restarting soft keyboard.

setInputType(InputType.TYPE_CLASS_NUMBER) changes keyboard layout to numeric text setInputType(InputType.TYPE_CLASS_TEXT) changes keyboard layout to normal text

like image 63
biegleux Avatar answered Sep 19 '22 15:09

biegleux