Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listview onItemClick sometimes not responding

I have a listview and a custom adapter.

on my list view I set this :

lv.setOnItemClickListener(...)

All is working fine. But When I start scrolling it doesn't. While I scroll down slowly it is stable (onItemClick is called) but when I scroll down more quickly or scroll down & up several times quickly, selecting an item do not fire an event. But if I wait a little or keep clicking an item or slowly scroll to the top, it randomly works.

Sometimes when I click an item it displays the yellow background (and onItemClick not called). Sometimes the orange background stay even after I stop touching (and onItemClick not called). Sometimes the background don't change at all (and onItemClick not called). And sometimes it works.

The items of the list are made of several textView / imageview / linearlayout (I set for each focusable=false it changed nothing) dynamically inflated with a view holder.

Do someone has an idea of what is wrong or have an idea how to debug it ?

(The source code is too big to be pasted here, I can send you the source code or the apk if you wish)

like image 566
jpprade Avatar asked Mar 06 '11 18:03

jpprade


2 Answers

Add this line to you parent layout of listview custom row xml file android:descendantFocusability="blocksDescendants"

Also in the textview of your inflator(Custom row view) layout just add:

android:focusable="false" android:focusableInTouchMode="false"

like image 102
Akshay Mehta Avatar answered Nov 06 '22 18:11

Akshay Mehta


I had a similar problem. My ListView items consisted of a LinearLayout containing an ImageView and a TextView. In addition to the following for my layout:

android:descendantFocusability="blocksDescendants"

and the following for my TextView and ImageView, as suggested in another answer:

android:focusable="false"
android:focusableInTouchMode="false"

I also added this this to my ImageView:

android:clickable="false"
like image 24
Greg Graham Avatar answered Nov 06 '22 19:11

Greg Graham