Note that there are some explanatory texts on larger screens.

plurals
  1. POFocusable EditText inside ListView
    text
    copied!<p>I've spent about 6 hours on this so far, and been hitting nothing but roadblocks. The general premise is that there is some row in a <code>ListView</code> (whether it's generated by the adapter, or added as a header view) that contains an <code>EditText</code> widget and a <code>Button</code>. All I want to do is be able to use the jogball/arrows, to navigate the selector to individual items like normal, but when I get to a particular row -- even if I have to explicitly identify the row -- that has a focusable child, I want that child to take focus instead of indicating the position with the selector.</p> <p>I've tried many possibilities, and have so far had no luck.</p> <p>layout:</p> <pre><code>&lt;ListView android:id="@android:id/list" android:layout_height="fill_parent" android:layout_width="fill_parent" /&gt; </code></pre> <p>Header view:</p> <pre><code>EditText view = new EditText(this); listView.addHeaderView(view, null, true); </code></pre> <p>Assuming there are other items in the adapter, using the arrow keys will move the selection up/down in the list, as expected; but when getting to the header row, it is also displayed with the selector, and no way to focus into the <code>EditText</code> using the jogball. Note: tapping on the <code>EditText</code> <em>will</em> focus it at that point, however that relies on a touchscreen, which should not be a requirement.</p> <p><code>ListView</code> apparently has two modes in this regard:<br> 1. <code>setItemsCanFocus(true)</code>: selector is never displayed, but the <code>EditText</code> can get focus when using the arrows. Focus search algorithm is hard to predict, and no visual feedback (on any rows: having focusable children or not) on which item is selected, both of which can give the user an unexpected experience.<br> 2. <code>setItemsCanFocus(false)</code>: selector is always drawn in non-touch-mode, and <code>EditText</code> can never get focus -- even if you tap on it.</p> <p>To make matters worse, calling <code>editTextView.requestFocus()</code> returns true, but in fact does not give the EditText focus.</p> <p>What I'm envisioning is basically a hybrid of 1 &amp; 2, where rather than the list setting if <em>all</em> items are focusable or not, I want to set focusability for a <em>single</em> item in the list, so that the selector seamlessly transitions from selecting the entire row for non-focusable items, and traversing the focus tree for items that contain focusable children.</p> <p>Any takers?</p>
 

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