Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: ListView elements with multiple clickable buttons
    primarykey
    data
    text
    <p>I've a <code>ListView</code> where every element in the list contains a TextView and two different Buttons. Something like this:</p> <pre><code>ListView -------------------- [Text] [Button 1][Button 2] -------------------- [Text] [Button 1][Button 2] -------------------- ... (and so on) ... </code></pre> <p>With this code I can create an <code>OnItemClickListener</code> for the whole item:</p> <pre><code>listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; list, View view, int position, long id) { Log.i(TAG, "onListItemClick: " + position); } } }); </code></pre> <p>However, I don't want the whole item to be clickable, but only the two buttons of each list element.</p> <p>So my question is, how do I implement a onClickListener for these two buttons with the following parameters:</p> <ul> <li><code>int button</code> (which button of the element has been clicked)</li> <li><code>int position</code> (which is the element in the list on which the button click happened)</li> </ul> <hr> <p><strong>Update:</strong> I found a solution as described in my answer below. Now I can click/tap the button via the touch screen. However, I can't manually select it with the trackball. It always selects the whole list item and from there goes directly to the next list item ignoring the buttons, even though I set <code>.setFocusable(true)</code> and <code>setClickable(true)</code> for the buttons in <code>getView()</code>.</p> <p>I also added this code to my custom list adapter:</p> <pre><code>@Override public boolean areAllItemsEnabled() { return false; } @Override public boolean isEnabled(int position) { return false; } </code></pre> <p>This causes that no list item is selectable at all any more. But it didn't help in making the nested buttons selectable.</p> <p>Anyone an idea?</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.
 

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