title: Programmatically setting up password dots in EditText
body: <p>I've been attempting to programmatically set up my edittext as a password field as follows:</p>
  
  <p>Method 1:</p>
  
  <pre><code>password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
  </code></pre>
  
  <p>Method 2:</p>
  
  <pre><code>password.setTransformationMethod(PasswordTransformationMethod.getInstance());
  </code></pre>
  
  <p>Method 3:</p>
  
  <pre><code>password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
  </code></pre>
  
  <p>Method 4:</p>
  
  <pre><code>    public class MyPasswordTransformationMethod extends PasswordTransformationMethod {
      @Override
      public CharSequence getTransformation(CharSequence source, View view) {
          return new PasswordCharSequence(source);
      }
  
      private class PasswordCharSequence implements CharSequence {
          private CharSequence mSource;
          public PasswordCharSequence(CharSequence source) {
              mSource = source; // Store char sequence
          }
          public char charAt(int index) {
              return '*'; // This is the important part
          }
          public int length() {
              return mSource.length(); // Return default
          }
          public CharSequence subSequence(int start, int end) {
              return mSource.subSequence(start, end); // Return default
          }
      }
  };
  
  // Call the above class using this:
  text.setTransformationMethod(new MyPasswordTransformationMethod());
  </code></pre>
  
  <p>I created my edittext as follows:</p>
  
  <pre><code>        // Create the password edittext
      EditText etPwrd = new EditText(this);
  
      // Customise the password edittext
      etPwrd.setLayoutParams(etPwrdParams);
      etPwrd.setBackgroundResource(R.drawable.etlogin);
      etPwrd.setTextSize(18f);
      etPwrd.setLongClickable(false);
      etPwrd.setPadding (5,0,0,0);
      etPwrd.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
      etPwrd.setTransformationMethod(new MyPasswordTransformationMethod());
      etPwrd.setTypeface(officialRegularFont);
      //etPwrd.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
      //etPwrd.setTransformationMethod(PasswordTransformationMethod.getInstance());
      etPwrd.setSingleLine();
      etPwrd.setHint(R.string.password_text);
      etPwrd.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
  
          @Override
          public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
              return false;
          }
  
          @Override
          public boolean onCreateActionMode(ActionMode mode, Menu menu) {
              return false;
          }
  
          @Override
          public void onDestroyActionMode(ActionMode mode) {
          }
  
          @Override
          public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
              return false;
          }
  
      });
  </code></pre>
  
  <p>I have been unsuccessful using all of the above approaches as the edittext still displays the characters when a user types into them.</p>
  
  <p>I'm aware in XML how to set up an edittext to be a password field but I need to this programmatically.</p>