Android authentication Two

Source: Internet
Author: User

<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="match_parent"android:orientation="Vertical"Tools:context=". Mainactivity"> <TextView android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:id="@+id/name"Android:text="Name:"/> <edittext android:id="@+id/edittext_name"Android:layout_width="fill_parent"Android:layout_height="wrap_content"Android:hint="Please enter text information"/> <TextView android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:id="@+id/age"Android:text="Age:"/> <edittext android:id="@+id/edittext_age"Android:layout_height="wrap_content"Android:layout_width="fill_parent"Android:hint="Please enter your age"/> <button android:id="@+id/btnsubmit"Android:layout_height="wrap_content"Android:layout_width="wrap_content"Android:text="Submit Validation"/> </LinearLayout>
Package com.example.fourandroid;  Import Android.annotation.SuppressLint;  Import android.app.Activity;  Import Android.app.AlertDialog;  Import Android.content.DialogInterface;  Import Android.os.Bundle;  Import Android.view.View;  Import Android.view.View.OnClickListener;  Import Android.widget.Button;  Import Android.widget.EditText;    Import Android.widget.Toast; @SuppressLint ("Showtoast")   Public classMainactivity extends Activity {PrivateEditText Edittext_name; PrivateEditText Edittext_age; PrivateButton btnsubmit; @Overrideprotected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);                    Super.setcontentview (R.layout.activity_main); //get component information;          This. Edittext_name =(EditText) Super.findviewbyid (r.id.edittext_name);  This. Edittext_age =(EditText) Super.findviewbyid (r.id.edittext_age); //sets the Click event to the button;          This. btnsubmit =(Button) Super.findviewbyid (r.id.btnsubmit);  This. Btnsubmit.setonclicklistener (NewMybtnsubmitimpl ()); }         Public classMybtnsubmitimpl implements onclicklistener{@Override Public voidOnClick (View v) {Boolean Bol=true; String Age= Mainactivity. This. Edittext_age.gettext (). toString (); String name= Mainactivity. This. Edittext_name.gettext (). toString (); //Instantiate dialog box; Alertdialog.builder Builder =NewAlertdialog.builder (V.getcontext ()); Builder.settitle ("Prompt Information"); //determine if name is empty;             if(Name = =NULL|| Name.trim (). Length () = =0||"". Equals (Name.trim ())) {Builder.setmessage ("name cannot be empty, please enter the information."); Builder.setpositivebutton ("Confirm",NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich)                       {Setresult (RESULT_OK);                                    }                  }); //set focus information; Mainactivity. This. edittext_name.setfocusable (true); Mainactivity. This. Edittext_name.setfocusableintouchmode (true); Mainactivity. This. Edittext_name.requestfocus (); Mainactivity. This. Edittext_name.requestfocusfromtouch ();                  Builder.show (); //identifies this text box property as empty; Bol =false; return; }                            //determine if the address is empty;             if(age = =NULL||"". Equals (age) | | Age.trim (). Length () = =0) {builder.setmessage ("Age cannot be empty, please enter information."); //Add a OK button to the dialog box; Builder.setpositivebutton ("Determine",NewDialoginterface.onclicklistener () {//listen for click events;                      Public voidOnClick (Dialoginterface Dialog,intWhichbutton) {Setresult (RESULT_OK);//determining button events;                     }                   }) ; //set address focus; Mainactivity. This. edittext_age.setfocusable (true); Mainactivity. This. Edittext_age.setfocusableintouchmode (true); Mainactivity. This. Edittext_age.requestfocus (); Mainactivity. This. Edittext_age.requestfocusfromtouch (); //display the prompt box; builder.show (); //identifies this text box property as empty; Bol =false; return; }                            if(BOL) {//sets the prompt information. Toast.maketext (mainactivity. This,"Congratulations, the verification is successful.", Toast.length_long). Show (); }          }      }  }  

Android authentication Two

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.