Simple usage of andriod 1

Source: Internet
Author: User

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

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.