I found this somewhere after googling
There will be case that your custom list item doesn’t respond when you click…so what’s the reason and what’s the solution?
Here several problems and solutions:
1. Scenario: list item layout contains CheckBox
Problem: OnItemClickListener doesn’t respond.
Reason: CheckBox is also having its own click listener by default to change its state, and it overrides the container ListView.
Solution: remove focus on CheckBox by setting these attributes to “false”
1 2 android:focusable="false" android:focusableInTouchMode="false"
2. Scenario: random
Problem: OnItemClickListener just doesn’t repond any at all!!!!
Reason: No idea..
Solution: in code, just set OnItemClickListener before setting Adapter. It works randomly @@!
3. Scenario: list item contains ImageButton
Problem: OnItemClickListener just doesn’t repond any at all!!!!
Reason: No idea!!!
Solution: in code, set ImageButton focus to “false”
1 2 ImageButton button = (ImageButton) convertView.findViewById(R.id.imageButton); button.setFocusable(false);
4. Scenario: list item contain TextView
Problem: OnItemClickListener just doesn’t repond.
Reason: I think you have set this attribute to TextView: android:inputType=”textMultiLine”
Solution: just remove that attribute, using android:minLines/android:maxLines instead.
5. Scenario: list item contain a TextView that is linked to website URL or whatever “mailto:” things
Problem: OnItemClickListener just doesn’t repond.
Reason: the TextView overrides focus of list item.
Solution: just remove attribute “android:autoLink” on TextView.
position不是一定从0开始的
若使用ArrayAdapter绑定ListView。 在onItemClickListener中 使用 if (postion == 1(数组坐标))检测而不是 if (array[position] == array数组position坐标位置)
参考:
http://www.dewen.io/q/6038/Android+ListView%E4%B8%ADonItemClick%E6%97%A0%E6%B3%95%E5%BE%97%E5%88%B0%E5%93%8D%E5%BA%94%EF%BC%9Fselector%E4%B8%AD%E7%9A%84pressed%E7%8A%B6%E6%80%81%E5%A6%82%E4%BD%95%E8%BF%9B%E8%A1%8C%E5%B1%8F%E8%94%BD%EF%BC%9F
http://www.cnblogs.com/livesoft/archive/2011/02/12/1951762.html