The first is the design of the XML layout
<?xml version="1.0"encoding="Utf-8"? ><linearlayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="Vertical"Android:layout_width="fill_parent"Android:layout_height="fill_parent"> <textview android:id="@+id/tv"Android:layout_width="fill_parent"Android:layout_height="wrap_content"/><edittext android:id="@+id/et"Android:layout_width="fill_parent"Android:layout_height="wrap_content"/> <checkbox android:id="@+id/cb"Android:layout_width="fill_parent"Android:layout_height="wrap_content"Android:text="Show or hide passwords"/><button android:id="@+id/bt"Android:layout_width="fill_parent"Android:layout_height="wrap_content"Android:text="display the input string"/></linearlayout>
And then the activity.
1 Package Com.pocketdigi.edit;2 3 import android.app.Activity;4 import Android.os.Bundle;5 import Android.text.method.HideReturnsTransformationMethod;6 import Android.text.method.PasswordTransformationMethod;7 import Android.view.View;8 import Android.view.View.OnClickListener;9 import Android.widget.Button;Ten import Android.widget.CheckBox; One import Android.widget.CompoundButton; A import Android.widget.EditText; - import Android.widget.TextView; - import Android.widget.CompoundButton.OnCheckedChangeListener; the - Public classMain extends Activity { - /** Called when the activity is first created.*/ - EditText et; + CheckBox CB; - TextView TV; + Button bt; A @Override at Public voidonCreate (Bundle savedinstancestate) { - super.oncreate (savedinstancestate); - Setcontentview (r.layout.main); -et=(EditText) Findviewbyid (r.id.et); - Et.settransformationmethod (Passwordtransformationmethod.getinstance ()); incb=(CheckBox) Findviewbyid (R.ID.CB); -tv=(TextView) Findviewbyid (r.id.tv); tobt=(Button) Findviewbyid (R.ID.BT); + Bt.setonclicklistener (show); - Cb.setoncheckedchangelistener (listener); the } *Oncheckedchangelistener listener=NewOncheckedchangelistener () { $ Panax Notoginseng @Override - Public voidoncheckedchanged (Compoundbutton Buttonview, the Boolean isChecked) { + //TODO auto-generated Method Stub A if(isChecked) { the Et.settransformationmethod (Hidereturnstransformationmethod.getinstance ()); + //If selected, displays the password -}Else{ $ Et.settransformationmethod (Passwordtransformationmethod.getinstance ()); $ //Otherwise hide the password - } - the } - Wuyi }; theOnclicklistener show=NewOnclicklistener () { - Wu @Override - Public voidOnClick (View v) { About //TODO auto-generated Method Stub $ Tv.settext (Et.gettext ()); - //After you click the button, TextView displays the input string - } - A }; +}
Android Input Password Hide display input string