Monday, May 14, 2012

Code to show password in Android?



Note:* To show the dots instead of the password set the PasswordTransformationMethod:yourEditText.setTransformationMethod(new PasswordTransformationMethod());*To re-show the readable password, just pass null as transformation method:yourEditText.setTransformationMethod(null);- Take CheckBox in layout.- Give id as chkShowPassword.- Bind it as shown below.- Import setOnClickListener to handle the click event.- And perform the action.


private void showPassword() {
final CheckBox checkbox = (CheckBox) findViewById(R.id.chkShowPassword);
checkbox.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks, depending on whether it’s now
// checked
if (((CheckBox) v).isChecked()) {
etxtPassword.setTransformationMethod(null);
} else {
etxtPassword
.setTransformationMethod(new PasswordTransformationMethod());
}
}
});
}

No comments:

Post a Comment