I'm totally new to Android.
I would like to put in a textbox where user can enter an IP address ... but how do I limit the user to only enter numbers? ... and how do I validate?
Is there a ready-made-ip-address-textbox "out there" I can use?
Thanks!
Mojo
This example demonstrates how do I get the IP address of android device programmatically. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.java. ...
Set a TextBox in your form or user control and clear its contents. Change the type of this TextBox from System.Windows.Forms.TextBox to rj2_cs.IPAddressTextBox in code editor. Then you can change the properties of the IP textbox like you want.
What I've found that works is to set an EditText to use android:inputType="phone", so the input is restricted to digits, period, and a handful of other characters. However, this will only let you input IPV4 addresses, since it's digits only. For validation, you'll have to get the input text and parse it by hand.
The router automatically assigns a local IP address to every device that connects to it. This address can be used to identify each device on a network and connect them. For example, if you want to connect an app on your PC with your Android phone, then local IP address of at least one of the devices is needed.
What I've found that works is to set an EditText
to use android:inputType="phone"
, so the input is restricted to digits, period, and a handful of other characters. However, this will only let you input IPV4 addresses, since it's digits only. For validation, you'll have to get the input text and parse it by hand.
As far as ready-made input widgets, I haven't come across one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With