Android Tutorial

Android Tutorial Android Toast Button Widget In Android Tutorial Imageview Widget In Android Android Date Picker Example Android Time Picker Example Android Operating System Android Activity Android Architecture Android Content Providers Android Edittext Android Emulator Android Fragments Android Gridview Android Broadcast Receivers Event Handling In Android What Is Android Studio Android Navigation Drawer Android Recyclerview Android Scrollview Android Navigation Android Operating System Android ListView Android Studio Resources Android Studio's Layout Editor Android TextView Android Styles and Themes How To Show Image On An Android Application How To Insert An Email In Android Application In Android Version 8 How To Insert The Mobile Number On An Android Application Using Edittext Difference between android developer and web AdapterViewFlipper in Android with Example Android 9.0 Pie vs. Android 10, which one is better Android Development or Web Development which one is the best to choose Android Project Folder Structure Assets folder in Android How to reduce the size of APK in Android Top 7 Android App Development Books Top Programming Languages for Android Development Android Navigation Application Components Difference between android developer and web developer Event Handling in Android How to reduce the size of APK in Android Top 7 Android App Development Books Top Programming Languages for Android Development AdapterViewFlipper in Android with Example Android 9.0 “Pie” vs. Android 10, which one is better Android Development or Web Development which one is the best to choose Android EditText Android Fragments How to Update Gradle in Android Studio Navigation Drawer ScrollView What is Android Studio? Android Architecture Android Content Providers

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:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
    android:id="@+id/layout">
    <EditText
        android:id="@+id/editText9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="102dp"
        android:ems="10"
        android:inputType="number" />
</RelativeLayout>

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:

number=findViewById(R.id.editText);
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

MainActivity.java file:

if(number==9560146699){
Toast.makeText(MainActivity.this,"Welcome 9560146699",Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(MainActivity.this,"Not a valid user",Toast.LENGTH_SHORT).show();
}