Click how events are handled and the creation of the registration Form (ii) Implementation of login business logic

Source: Internet
Author: User

Business Flowchart:

Development steps:

    • Get user-entered account number and password
    • Using if logical statements for business logic judgment
    • Give the user the appropriate hints based on the results of the judgment

Code:

1  Public classLoginactivityextendsappcompatactivity {2 3     4     PrivateButton Btnlogin;5     PrivateEditText Txtaccount,txtpassword;6 7 @Override8     protected voidonCreate (Bundle savedinstancestate) {9 Ten         Super. OnCreate (savedinstancestate); One Setcontentview (r.layout.activity_login); A          -          This. Btnlogin = (Button) This. Findviewbyid (R.id.btnlogin);  -          This. Txtaccount = (EditText) This. Findviewbyid (R.id.txtaccount);//get user-entered account number the          This. Txtpassword = (EditText) This. Findviewbyid (R.id.txtpassword);//get the password entered by the user -          -          This. Btnlogin.setonclicklistener (NewViewocl ()); -        +     } -     +  A     Private  classViewoclImplementsview.onclicklistener{ at @Override -          Public voidOnClick (View v) { -             Switch(V.getid ()) { -                  CaseR.id.btnlogin: -String account=Txtaccount.gettext (). toString (). Trim (); -String password=Txtpassword.gettext (). toString (). Trim (); in                     BooleanLogin_flag =false; -  to                     if("admin". Equals (account) && "123". Equals (password)) {//using if logical statements for business logic judgment +login_flag=true; -                     } the  *String message = Login_flag? "Welcome login," +account: "Incorrect account or password";//give the user the appropriate hints based on the results of the judgment $ Toast.maketext (Getapplicationcontext (), Message,toast.length_long). Show ();Panax Notoginseng                      Break; -                  CaseR.id.btnregister: the                      Break; +                 default: Break; A             } the         } +     } -}
Loginactivity.java

Run:

Click how events are handled and the creation of the registration Form (ii) Implementation of login business logic

Related Article

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.