Get only numeric value from edittext in android

Open display only numeric keypad on edittext click so user can insert alone numbered value not alphabetic charters.

Sometimes on android apps there are a limitation set by application builder that when ever you click on editText box it will just open numeric keypad so app user cannot enter both alphabetic and numeric values on application user can only insert numbered value. This feature is basically used to enter phone number, credit card numbers, ATM pin, city pin code. So here is the complete step by step tutorial for Get only numeric value from edittext in android .

android-project-download-code-button

How to Get only numeric value from edittext in android .

App developer can set only numeric value limitation using android:inputType=”number” attribute into edittext box.

Code for MainActivity.java file.

package com.android_examples.com.edittextnumeric;
import android.app.Activity;
import android.os.Bundle;


public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }

}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.android_examples.com.edittextnumeric.MainActivity" >

 <EditText
 android:id="@+id/editText1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:ems="10"
 android:inputType="number" >

 <requestFocus />
 </EditText>

</RelativeLayout>

Screenshot:

Get only numeric value from edittext in android

Click Here To Download Get only numeric value from edittext in android project.

Leave a Reply

Your email address will not be published. Required fields are marked *