I have a ListView and with a Timer I control the scroll movement of this list by calling smoothScrollToPositionFromTop(position, offset, duration). The ListView has a listener for OnItemClickListener.
If an item is clicked while the smooth scroll is happening, the scroll stops but the onItemClick event is not triggered. In order to do so you need to click again on the item.
I want to know how to override this behaviour. I mean, if I click on an item while the smooth scroll is happening, apart from stopping the scroll, I want to trigger onItemClick on the item clicked.
I really don’t know if there is an easy way to do this. I tried with a GestureDetector for the OnTouchListener of the list and I listen to the onSingleTapConfirmed in order to call performClick in there, but I don’t know how to get the position of the item being press from the MotionEvent.
I finally found a solution by using the
GestureDetector:In my case, I added what I was doing in
onItemClickinsideonSingleTapConfirmedand removed theOnItemClickListenerfrom the list. That’s why I also added theplaySoundEffectfunction to simulate the click.In the last line I disable highlight on
ListViewclick since lines got highlighted only when the smooth scroll was not happening. By disabling it I get the same behaviour for every click.