Listview onItemClick sometimes not responding

I have a list and a custom adapter.

in my list view I installed this:

lv.setOnItemClickListener (...)

Everything is working fine. But when I start scrolling, it is not. While I am slowly scrolling, it is stable (onItemClick is called), but when I scroll down faster or scroll down and up several times faster, selecting an item does not produce an event. But if I wait a bit or continue to click on an item or slowly scroll up, it randomly works.

Sometimes, when I click an element, it displays a yellow background (and onItemClick is not called). Sometimes the orange background remains even after I stop touching (and onItemClick is not called). Sometimes the background does not change at all (and onItemClick is not called). And sometimes it works.

The elements of the list consist of several textView / imageview / linearlayout (I set focusable = false for each this did not change anything), dynamically inflated using the view holder.

Does anyone have an idea of ​​what's wrong, or have an idea how to debug it?

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

+7
source share
2 answers

Add this line to the parent layout of the XML file of the listview android linelist: descendantFocusability = "blocksDescendants"

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

Android: focus = false; android: focusableInTouchMode = false

+2
source

I had a similar problem. ListView elements 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 to my ImageView:

 android:clickable="false" 
+1
source

All Articles