'How to get index value of a scrollview at certain position?

I have a horizontal scrollview like below with V as an overlay and it acts like a pointer:

   V
 [ 0 ] , [ 1 ] , [ 2 ] , [ 3 ] , [ 4 ] , [ 5 ] 
   ^

When I scroll, I would like to print the value or index that is in the current pointer. Eg. scroll until [2] and it will print "2".

   V
 [ 2 ] , [ 3 ] , [ 4 ] , [ 5 ] 
   ^

Could you guide me on how to achieve this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source