Android --- 05 --- simple logon demo

Source: Internet
Author: User

 
      
      
      
     
     
  
 



Package com. example. test_login; import android. app. activity; import android. OS. bundle; import android. view. view; import android. widget. editText; import android. widget. toast; public class MainActivity extends Activity {private EditText name; private EditText password; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); name = (EditText) findViewById (R. id. name); password = (EditText) findViewById (R. id. password);} public void click (View view) {if (name. getText (). toString (). equals ("abc") & password. getText (). toString (). equals ("abc") {// 1. context // MainActivity. this is the current Activity object // set because Toast is displayed in the current Activity. this // 2.res // text displayed by Toast // 3. duration Toast. makeText (MainActivity. this, "jump", Toast. LENGTH_SHORT ). show (); // show () display Toast} else {name. setError ("incorrect user name or password"); password. setError ("incorrect user name or password ");}}}


Result:





Click to bring up Toast.


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.