title: Android Remove selection EditText after long click
body: <p>I've got a <code>EditText</code> which I want to use in two ways</p>
  
  <ul>
  <li>When clicked everything is selected and the user can change the
  input. </li>
  <li>When long clicked the text color changes and for the rest
  nothing happens for the user.</li>
  </ul>
  
  <p>I've tried to clear its focus, but everytime I let go after a long click everything is selected. Probably because of the <code>android:selectAllOnFocus="true"</code> in the XML file. But I do want everything selected when the user just touches the ET, but not after a long press.</p>
  
  <p>The code that I've got so far is:</p>
  
  <p>main.java</p>
  
  <pre><code>ET = (EditText) findViewById(R.id.someET);
  ET.setRawInputType(Configuration.KEYBOARD_12KEY);
  ET.setOnEditorActionListener(new DoneOnEditorActionListener());
  ET.setOnLongClickListener(new myLongClickListener());
  
  class DoneOnEditorActionListener implements OnEditorActionListener {
  @Override
  public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
      if (actionId == EditorInfo.IME_ACTION_DONE) {
          v.clearFocus();
          InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
          imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
          return true;
      }
      return false;
  }
  }
  
  class MyLongClickListener implements OnLongClickListener{
  
  private boolean locked = false;
  
  @Override
  public boolean onLongClick(View view) {
      if(locked){
          ((EditText)view).setTextColor(0xFF000000);
      } else {
          ((EditText)view).setTextColor(0xFFFF0000);
      }
      locked =! locked;
      return true;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The DoneOnEditorActionListener is there when the user presses the enter/done button the ET will lose focus and the keyboard will hide.</p>