Enter specific characters in Android------edittext

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.