Using xml layout attributes
For this, you can use several xml attributes to your EditText xml definition (see android:inputType for available options)
Examples:
<EditText android:inputType="phone" ...
<EditText android:inputType="number" ...
<EditText android:inputType="numberSigned" ...
<EditText android:inputType="numberDecimal" ...
You can also both hint android to show digital keyboard and restrict input to acceptable characters with android:numeric
Examples:
<EditText android:numeric="integer" ...
<EditText android:numeric="signed" ...
<EditText android:numeric="decimal" ...
Programatically
Use EditText.setRawInputType(int)
with constants such as TYPE_CLASS_NUMBER you will find in android:inputType
or
EditText editView = new EditText(this);
editView.setKeyListener(new NumberKeyListener())
EditText editView = new EditText(this);
editView.setKeyListener(new DigitsKeyListener());
Hope this help