1. Jump from one activity to another activity, using intent.
In the onclick of the button, the following is the notation:
Public void Login (view view) { new Intent (); // set jump from relativeactivity to loginactivity Intent.setclass (relativeactivity. this, loginactivity. class ); // use Putextra to transfer data from one activity to another Intent.putextra ("name", "exclusive"); Intent.putextra ("password", "1234"); StartActivity (intent); }
Receive in a newly opened activity
PrivateEditText Loginnameedittext =NULL; PrivateEditText Loginpasswordedittext =NULL; protected voidonCreate (Bundle savedinstancebundle) {Super. OnCreate (Savedinstancebundle); Setcontentview (Layout.login); //requestwindowfeature (window.feature_no_title);Loginnameedittext =(EditText) Findviewbyid (r.id.loginname); Loginpasswordedittext=(EditText) Findviewbyid (R.id.loginpassword); //received the intent that passed overIntent Intent =getintent (); //receiving data from a intentString namestring = Intent.getstringextra ("name"); String passwordstring= Intent.getstringextra ("Password"); Loginnameedittext.settext (namestring); Loginpasswordedittext.settext (passwordstring); }
2, determine whether the text box is empty, and pop-up hints, reference links: http://zhouhaitao.iteye.com/blog/1831523
Public voidLogin (view view) {String loginnamestring=Loginnameedittext.gettext (). toString (); String loginpasswordstring=Loginpasswordedittext.gettext (). toString (); LOG.D ("Loginactivity", loginnamestring); //determine if null equals is used if(Loginnamestring.equals ("")) { //This tip is to show that auto disappears.Toast.maketext (loginactivity. This, "Please enter user name", Toast.length_short). Show (); return; } Else{toast.maketext (loginactivity). This, "already there.", Toast.length_short). Show (); } if(Loginpasswordstring.equals ("")) { //This is the alert prompt box, you can set the title, content and buttons, do not forget the last show NewAlertdialog.builder (View.getcontext ()). Settitle ("hint"). Setmessage ("Password cannot be empty!"). "). Setpositivebutton ("OK",NULL). Show (); } }
Simple usage of andriod 1