Open keyboard only on second touch on an EditText
<p>I am trying to achieve the following: my layout has a number of EditTexts. When the user touches one of the EditTexts for the first time, the keyboard should not open but the EditText should just gain focus. This is because I am doing a calculation in the EditText when it gains focus and I want to display the result to the user. Then when the user has seen the result he can touch the EditText again which will selectAll and open the keyboard to enter a new number.</p>

<p>This is the code I am using right now:</p>

<pre><code>myEditText.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if(iFocus == R.id.eTmyEditText) {
                if(iCount == 3) {
                    myEditText.selectAll();
                    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(myEditText, InputMethodManager.SHOW_IMPLICIT);
                }
                if(iCount &gt; 3) return false;
                iCount++;
            }
            else iCount=0;
            myEditText.requestFocus();
            return true;
        }
});
</code></pre>

<p>I am using the <code>iCount</code> variable to distinguish the first touch from the second and the ones which will follow. <code>iFocus</code> is set in the focusChangeListener and holds the last EditText which had focus.</p>

<p>The code is working fine sometimes but not always. From time to time the keyboard is not opening or already on the first touch, sometimes the text is not selected, etc.</p>

<p>Is it possible that the TouchEvent bounces somehow? So that the TouchListener is executed more often than I would expect it to be? I also tried to separate the down event and the up event but this does not help.</p>

<p>Has anyone a good idea how what I am trying to do could be implemented in a better way? Thanks</p>

<hr>

<p><strong>EDIT</strong>: this is my final solution:</p>

<pre><code>    myEditText.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
          switch (event.getAction()) {
          case MotionEvent.ACTION_DOWN:
              myEditText.requestFocus();
              if(iCount == 1){
                  myEditText.postDelayed(new Runnable() {
                      public void run() {
                          InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                          manager.showSoftInput(myEditText, 0);
                          myEditText.selectAll();
                      }
                  }, 200);
              }
              iCount++;
              break;

          default:
              break;
          }
          if(iCount &gt;= 2) return false;
          else return true;
        }
    });
</code></pre>
