Hide and display the entered password in the Android Layout

Source: Internet
Author: User

Hide and display the entered password in the Android Layout

 
  
   
         
    
   
      
      
   
            
             
     
    
   
  
 

Package com. banana. k08.home; import android. app. activity; import android. OS. bundle; import android. text. method. hideReturnsTransformationMethod; import android. text. method. passwordTransformationMethod; import android. view. menu; import android. view. menuItem; import android. view. view; import android. widget. button; import android. widget. checkBox; import android. widget. compoundButton; import android. widget. editText; import android. widget. toast; public class MainActivity extends Activity {private EditText id, password; private CheckBox cb; private Button btn1; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); id = (EditText) findViewById (R. id. tv1); password = (EditText) findViewById (R. id. password); cb = (CheckBox) findViewById (R. id. check); // select whether to display the password cb. setOnCheckedChangeListener (new CompoundButton. onCheckedChangeListener () {@ Override public void onCheckedChanged (CompoundButton compoundButton, boolean B) {if (cb. isChecked () {password. setTransformationMethod (HideReturnsTransformationMethod. getInstance ();} else {password. setTransformationMethod (PasswordTransformationMethod. getInstance () ;}}); findViewById (R. id. btnl ). setOnClickListener (new View. onClickListener () {@ Override public void onClick (View v) {String name = id. getText (). toString (); String pass = password. getText (). toString (); if (name. equals (admin) & pass. equals (admin) {Toast. makeText (getApplicationContext (), login successful, Toast. LENGTH_SHORT ). show ();} else {Toast. makeText (getApplicationContext (). Login Failed. Please enter again, Toast. LENGTH_SHORT ). show ();}}});}}


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.