RSS

Code to show password in Android

26 Sep

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());
}
}
});
}

Advertisements
 
Leave a comment

Posted by on September 26, 2011 in Android Source Code

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: