Android: Set Password Hiding and display

Source: Internet
Author: User

Main. xml:

<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayoutxmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<TextView
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/hello"
/>
<EditText
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: inputType = "textPassword"
Android: id = "@ + id/mima"
/>
<CheckBoxandroid: text = "display password" android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" android: id = "@ + id/xianshifou"/>
</LinearLayout>

 

 

Java code:


Public class M extends Activity {

PrivateEditText et;
PrivateCheckBox cb;
Public voidonCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );

Et = (EditText) findViewById (R. id. mima );
Cb = (CheckBox) findViewById (R. id. xianshifou );
Cb. setOnCheckedChangeListener (new OnCheckedChangeListener (){

@ Override
Public void onCheckedChanged (CompoundButton arg0, boolean arg1 ){
// TODO Auto-generated method stub
If (cb. isChecked ()){
// Set the EditText password to visible
Et. setTransformationMethod (HideReturnsTransformationMethod. getInstance ());
} Else {
// Set the password to hidden
Et. setTransformationMethod (PasswordTransformationMethod. getInstance ());
}
}

});
}
}

Author: get123

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.