I've tested the following solution on SDK levels 8 and 16.
In getView()
setFocusable(false);
setClickable(false);
rather than setting them true in the Adapter's getView()
does what I think the original question wanted, and means that an OnItemClickListener
gets called, provided that an OnClickListener
is not set in getView()
.
I'm assuming that anything you can do in an View's OnClickListener
you can do just as easily in a ListView
's OnItemClickListener
.
(setOnClickListener
on a View implicitly sets the view to be clickable, which prevents the ListView
's corresponding OnItemClickListener
getting called, apparently.)
The behaviour is as one would expect, in terms of the ImageButton
's visual state when the item is pressed or rolled over.
The solution is a slight illusion, in that it is the list item that's being pressed not the ImageButton
itself, so if the button doesn't occupy whole list item, clicking somewhere else in the item will still make the button's drawable state reflect the click. Same for focus. That might be a price worth paying.