I have the following EditText:
<EditText
android:id="@+id/ip"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:singleLine="true"
android:inputType="numberDecimal">
</EditText>
I want to use this to get ip address. But it will not allow me to type '.' (period sign) more than once because the inputtype is set to numberDecimal. Any suggestion on how to get more than one '.' while setting inputType to numbers.
Found this solution on another thread.
You should use the att:
android:digits="0123456789."
http://developer.android.com/reference/android/widget/TextView.html#attr_android:digits
This works perfectly keyboard with numbers and decimal by adding android:inputType="number|numberDecimal" and android:digits="0123456789."
Example
You need to create your own
InputFilter
: http://developer.android.com/reference/android/text/InputFilter.htmlTake a look at this answer I wrote some time ago: How to set Edittext view allow only two numeric values and two decimal values like ##.##
Update - sample code
Here is an adaptation to that filter to validate ips. It checks for the presence of four digits, separated by dots and none of them bigger than 255. The validation occurs in real time, i.e., while typing.