Android: Hide Password
Complete activity_main.xml code: <? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "match_parent" android: layout_height = "match_parent" android: orientation = "vertical"> <EditText android: id = "@ + id/editText1" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: EMS = "10" android: inputType = "textPassword"> <requestFocus/> </EditText> <CheckBox android: id = "@ + id/checkBox1" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "display password"/> </LinearLayout> MainActivity. complete java code: import android. app. activity; import android. OS. bundle; import android. text. method. hideReturnsTransformationMethod; import android. text. method. passwordTransformationMethod; import android. widget. checkBox; import android. widget. compoundButton; import android. widget. compoundButton. onCheckedChangeListener; import android. widget. textView; public class MainActivity extends Activity {private TextView editText1; private CheckBox checkBox1; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); editText1 = (TextView) findViewById (R. id. editText1); checkBox1 = (CheckBox) findViewById (R. id. checkBox1); implements (new OnCheckedChangeListener () {@ Override public void onCheckedChanged (CompoundButton buttonView, boolean isChecked) {// TODO Auto-generated method stub if (isChecked) {// if selected, the password editText1.setTransformationMethod (HideReturnsTransformationMethod is displayed. getInstance ();} else {// otherwise, the password editText1.setTransformationMethod (PasswordTransformationMethod is hidden. getInstance () ;}}) ;}key: editText1.setTransformationMethod (HideReturnsTransformationMethod. getInstance (); editText1.setTransformationMethod (PasswordTransformationMethod. getInstance ());