Activity_main.xml:
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" fill_parent "android:layout_height=" Fill_parent "Android:orienta tion= "vertical" 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.example.edittextdemo2.MainActivity "> <textview Android:layout_widt H= "Wrap_content" android:layout_height= "wrap_content" android:text= "Use Android:digits attribute (enter number)"/> < EditText android:id= "@+id/num" android:layout_width= "200DP" android:layout_height= "Wrap_content" Android:layout_margin= "10DP" android:digits= "0123456789"/> <textview android:layout_width= "wrap _content "android:layout_height=" Wrap_content " Android:text= "Using the Android:digits attribute (enter 26 lowercase letters)"/> <edittext android:layout_width= "200DP" Android: layout_height= "Wrap_content" android:layout_margin= "10DP" android:digits= "qwertyuiopasdfghjklzxcvbnm"/> <textview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:text = "Use Android:inputtype property (input number)"/> <edittext android:layout_width= "200DP" android:layout_height= "WR Ap_content "android:layout_margin=" 10DP "android:inputtype=" Number|textcapcharacters "/> <TextView Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "using Android:inpu Ttype Property (Input e-mail) "/> <edittext android:layout_width=" 200DP "android:layout_height=" Wrap_content " Android:layout_margin= "10DP" android:inputtype= "textemailaddress"/> <textview android:layou T_width= "Wrap_content" android:layout_height= "Wrap_content" android:text= "Use Android:numeric attribute (enter signed floating-point number)"/> <edittext Android:layout_width= "200DP" android:layout_height= "wrap_content" android:layout_margin= "10DP" an Droid:inputtype= "textemailaddress" android:numeric= "decimal|signed"/> <button android:id= "@+id/but Ton "android:layout_width=" 200DP "android:layout_height=" Wrap_content "android:text=" Confirm "/></li Nearlayout>
Mainactivity.java:
Import Android.app.activity;import android.os.bundle;import Android.view.menu;import Android.view.MenuItem;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.edittext;public class Mainactivity extends Activity implements Onclicklistener{private EditText num; Private button button, @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate ); Setcontentview (r.layout.activity_main); num = (EditText) Findviewbyid (r.id.num); button = (Button) Findviewbyid ( R.id.button); Button.setonclicklistener (this);} @Overridepublic void OnClick (View v) {//TODO auto-generated method stubstring value = Num.gettext (). toString (); if (value = = NULL | | Value.trim (). Equals ("")) {num.seterror ("Please enter Content"); return;}}
Enter specific characters in Android------edittext