Android Input Password Hide display input string

Source: Internet
Author: User

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

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.