Search code examples
javaandroidlistactivityandroid-listview

Android ListView - onListItemClick does not work properly


I created a ListView in Android, and a corresponding ListActivity. Each individual item in the ListView has just one TextView (I plan to add an image and a CheckBox later).The ListActivity overrides the onListItemClick to perform certain tasks on click of any item on the list.

Heres whats happening -

  • When I first tried clicking on any item, nothing happened.
  • I then tried setting the properties "Focusable" and "Focusable in Touch Mode" to false for the TextView, as mentioned here, here and here. The List items started recognizing clicks, but only when I clicked somewhere away from the TextView. Whenever I tried clicking on the TextView or anywhere near it, it did not work.
  • I also tried changing various attributes like Clickable, but nothing has worked so far.

Any idea what I could be doing wrong ?

Thanks


Solution

  • After playing around with virtually every attribute in my TextView, I finally found the reason why it was not working. It was because of the attribute android:inputType="text" in my TextView. I'm not sure why I added that piece of code (I probably copied the TextView from one of my other applications), but removing it solves my problem.