Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can try keeping a track of which <code>EditText</code> has been clicked. For this, create a EditText variable:</p> <pre><code>EditText etHasFocus; </code></pre> <p>In addition to adding <code>OnFocusChangeListener</code>, add an <code>OnClickListener</code> as well:</p> <pre><code>valueET.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { etHasFocus = (EditText) v; } }); </code></pre> <p>Now, inside your <code>OnFocusChangeListener</code>, make the following changes:</p> <pre><code>valueET.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if(!hasFocus) { if(!updateScore(v.getId())) { // Clear focus from another EditText if (etHasFocus != null &amp;&amp; v.getId() != etHasFocus.getId()) { etHasFocus.clearFocus(); } v.requestFocus(); } } } }); </code></pre> <p><strong>Edit:</strong></p> <p>You are right. the <code>onClick(View)</code> method is called on second click. I can suggest you an alternate approach. I have tried it and its working fine: </p> <p>Create a EditText variable:</p> <pre><code>EditText etCurrent; </code></pre> <p>Set an <code>OnTouchlistener</code> on each EditText:</p> <pre><code>valueET.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (etCurrent != null) { if (etCurrent.getId() != v.getId()) { if (!check(etCurrent.getId())) { etCurrent.setSelection(0, etCurrent.getText().toString().length()); return true; } else { etCurrent = (EditText) v; } } } else { etCurrent = (EditText) v; } } return false; } }); </code></pre> <p>Remove <code>OnClickListener</code>, <code>onFocusChangeListener</code> and <code>etHasFocus</code>.</p> <p>You don't need to initialize <code>etCurrent</code> as <code>if (etCurrent != null) { } else { }</code> takes care of that.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload