Had list view using custom adapter and found that onItemClickListener would not work. Found answer in stackoverflow.
Apparently the listener won’t work if any row item contains a focusable or clickable view. The solution is the following line, which I inserted into the top section of the row item layout.
android:descendantFocusability="blocksDescendants"
Apparently you can also do it programmatically:
listView.setDescendantFocusability(int focus);
where ‘focus’ is one of
- ViewGroup.FOCUS_BEFORE_DESCENDANTS
- ViewGroup.FOCUS_AFTER_DESCENDANTS
- ViewGroup.FOCUS_BLOCK_DESCENDANTS
Another solution – one I haven’t tried – is for situations such as having a button on the row that you want to keep clickable. In such a case you add the following line in the button’s xml.
android:focusable="false"