Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What android:inputType should I use for entering an IP Address and hostname?

I am building a small Android app where the user will enter an IP address or a hostname into an EditText widget. 90% of the time they will be entering an IP address, the rest of the time - a hostname.

So naturally, I want to make it easy for them to enter an IP address, but the ability to switch to alpha numerics for hostname entry is important.

I can't seem to find a good inputType. The numberDecimal initially seemed like a good shot, but it only allows one dot.

Ideally, I'd like to start with a standard keyboard that had the ?123 button pressed.

How do I get there?

like image 257
AngryHacker Avatar asked Dec 28 '11 22:12

AngryHacker


3 Answers

Try using android:inputType="number", but also set android:digits="0123456789.". Works for me.

like image 103
Bodacious Avatar answered Oct 14 '22 17:10

Bodacious


If you use inputType="phone" you gain access to a cut down keyboard containing Numbers and a Period character - this doesn't restrict the input with regards to the amount of Periods you can enter.

Please see this answer for validation while being entered.

like image 46
Graeme Avatar answered Oct 14 '22 19:10

Graeme


This works perfectly keyboard with numbers and decimal by adding android:inputType="number|numberDecimal" and android:digits="0123456789."

Example

 <EditText
    android:id="@+id/ip_address"
    android:inputType="number|numberDecimal"
    android:digits="0123456789."
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
like image 29
Munish Kapoor Avatar answered Oct 14 '22 17:10

Munish Kapoor