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