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 ();}}});}}