Tuesday, September 28, 2010

Android - onItemClick not being called on the item click of List

Well I am back with another classic problems.
I was making a very rich UI. I had to make a list with items containing check boxes, buttons, ImageView and so many like this and few of them like buttons and check boxes were selectable.
When I ran the application and tried to click an Item which was made up of few text, one button and one Image view, I didn't get callback in onItemClick() method.
I really surprised and thought, what the hell is that. Why not getting callback in the method.
I scratched my head, did so much googling and could not found the answer. When I removed button and check boxes it started getting events. Now I also wanted the event for the click on the buttons and checkboxes it was having.

Suddenly I thought I should make the button and checkboxes non-focusable which were actually getting focus when I was pressing down key on any item, and guess it worked. You should make each and every component in the list item as non-focusable then you would get the event for the click on that items as well as the full item click on event in onItemClick

Cheers!!!