title: Force EditText to lose focus when: some keyboard keys are pressed and when user clicks on something else in the activity
body: <p>I know this question has been asked in many different ways before, but even though I have looked at many other related questions about EditText focus, I have not found my solution. </p>
  
  <p>Here is what I want to achieve:</p>
  
  <ul>
  <li><p>When the user is done Editing an EditText I want it to loose focus.</p></li>
  <li><p>When the user hits outside the EditText I want such EditText to lose
  focus.</p></li>
  <li><p>Whenever the soft-keyboard hides or is hidden I want EditText
  to lose focus.</p></li>
  <li><p>Whenever the User hits ENTER or BACK ARROW in the soft-keyboard, the EditText focus should be cleared</p></li>
  </ul>
  
  <p>This is what I currently have:</p>
  
  <p>I have two EditText in an activity, which I will call EditText_1 and EditText_2 for simplicity so that we know which EditText I am talking about.</p>
  
  <ol>
  <li><p>When the user starts the activity, the EditText_1 would have no focus, a blinking cursor and the soft-keyboard would be hidden. I have already fixed that problem using;</p>
  
  <p><code>android:focusableInTouchMode="true"</code></p>
  
  <p>and</p>
  
  <p><code>android:focusable="true"</code></p></li>
  <li><p>After the previous fix in part1, when I start the activity and click on any EditText, it will gain focus, however, when I am done editing such clicked EditText and the soft-keyboard hides,  the EditText will not lose focus and the cursor will still be blinking.</p>
  
  <p>Another example happens when I am editing an EditText and click any other button outside the editText, it will not force EditText to lose focus or hide the keyboard.  </p></li>
  </ol>
  
  <p>The current solution I have is</p>
  
  <pre><code>public void onFocusChange(View v, boolean hasFocus){...}
  </code></pre>
  
  <p>so that, it will call some method such as force the EditText to lose focus:</p>
  
  <pre><code>EditText.clearFocus();
  </code></pre>
  
  <p>and do not show that annoying blinking cursor once I know EditText loses its focus:</p>
  
  <pre><code>EditText.setCursorVisible(false);
  </code></pre>
  
  <p>However, because hitting Done or outside EditText do not force it to lose focus, onFocusChange will not be called all the times(as in the examples provided).</p>
  
  <p>Some of the solutions I cannot accept are:</p>
  
  <p>Set the cursor visibility to false in the XML activity file and never and anywhere change it back to true.</p>
  
  <pre><code>setCursorVisible(false);
  </code></pre>
  
  <p>I want the cursor to be seen when needed and to be hidden when it is not needed. </p>
  
  <p>Have a button that needs to be clicked by the user so that inside such button  all methods needed will be called. I mean, it is not user-friendly at all. Users do not want to be forced to click a button just to hide all focus, blinking cursors...</p>
  
  <p>Here comes the part many of you will tell me, every single of these issues have been solved in different questions. HOWEVER, I have not been able to implement multiple solutions which will do all points previously stated.</p>