How to insert the mobile number on an android application using EditText

Number Insertion in android application:

Sometimes while dealing with numbers, we don’t want to insert any string inside an number so, we premiliary define an EditText so we externally specify an EditText attribute as android:inputType=”number”  After specifying this attribute in the EditText, it will be used only to insert a number.

Step 1: Create a brand new android project.

Create New Android Project with Example | Tutorial and Example

Step 2: Go to the XML file and select the design.

Xml File selection | TutorialandExample

Step 3: Under the text option, find an option named as number.

Step 4: Drag and drop the number to your preview.

Drag and Drop your number to Preview

Step 5: After dragging the Number text, your XML part will look like this:

After step 5, your front end designing is completed.

Step 6:  Insert the following code in you Main Activity file:

import android.widget.EditText;

Step 7: Insert the following code in your MainActivity class:

private EditText number;

Step 8: Inside the onCreate method of your MainActivity class, insert the following code:

String num=number.getText().toString();

This will initialize the number instance.

Step 9: In the final step, you can use the String number to get the number inserted by the user.

Developer may check the number entered by the user against the number in his database via num String.

I would suggest you to take a button to insert the number from the user.

Insert the following code on your onCreate method inside the file: