title: ListView items focus behaviour
body: <p>I'm trying to create a <code>ListView</code> (with custom <code>CursorAdapter</code>) of <code>EditText</code> items such that <code>EditTexts</code> appear uneditable at first and become editable upon long click. Then the user would edit <code>EditText</code> contents and <code>EditText</code> would save changes to db upon losing focus. However I've run into a really nasty behaviour that prevents me from doing this.</p>
  
  <p>1) I've set my <code>EditTexts</code> to <code>android:focusable="false"</code> and <code>android:focusableInTouchMode="false"</code> in XML. </p>
  
  <p>2) I've created an <code>OnItemLongClickListener</code> in my <code>ListActivity</code> that does the following:</p>
  
  <pre class="lang-java prettyprint-override"><code>public boolean onItemLongClick(AdapterView&lt;?&gt; parent, View view, int position, long id)
  {
      Log.d("NLAc", "longClick called");
      EditText et = (EditText) view.findViewById(R.id.etFolderName);
      et.setFocusable(true);
      et.setFocusableInTouchMode(true);
      return true;
  }
  </code></pre>
  
  <p>3) And when I create views in my adapter I attach the following focus change listener:</p>
  
  <pre class="lang-java prettyprint-override"><code>public void onFocusChange(View v, boolean hasFocus) 
  {
      if (hasFocus)
  {
      EditText et = (EditText)v;
      Log.d(TAG, "hasFocus true called " + et.getText());
      et.setText("focused");
      et.setSelection(et.length());
  }
  else
  {
      EditText et = (EditText)v;
      Log.d(TAG, "hasFocus false called " + et.getText());
      et.setText("unfocused");
      et.setFocusableInTouchMode(false);
              //TODO Save to DB
  }
  </code></pre>
  
  <p>}</p>
  
  <p>What happens is that when I long click the very first item I get the following in the log:</p>
  
  <p><code>longClick called</code></p>
  
  <p><code>hasFocus true called item1</code></p>
  
  <p><code>hasFocus false called focused</code></p>
  
  <p>If I remove the line setting focusable to false (<code>et.setFocusableInTouchMode(false);</code>) I get another <code>hasFocus true called unfocused</code>.
  Apparently things go like this:</p>
  
  <p>1) <code>EditText</code> gets focus when set focusable</p>
  
  <p>2) <code>LinearLayour</code> containing my <code>ListView</code> loses focus and calls internal <code>unFocus()</code> on all it's children including my <code>EditText</code></p>
  
  <p>3) <code>EditText</code> loses focus</p>
  
  <p>4) <code>EditText</code> gets focus - for whatever reason now.</p>
  
  <p>This behaviour prevents me from disabling <code>EditText</code> upon losing focus or making it unfocusable until the next long click comes through which is what I want.
  Can anyone suggest what I may be missing? Or explain this behaviour? Any solutions appreciated.</p>