This is a very annoying problem. When flicking through a ViewPager, the "settled" state fires a second AFTER the page has settled. In other words: the animation is already finished a while before the correct state is fired...
B4X:
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: Hello World
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
Sub Process_Globals
End Sub
Sub Globals
Private VP As ViewPager: ' https://www.b4x.com/android/forum/threads/viewpager-cleaned-up-viewpager.75342/
Private PC As PageContainer
End Sub
Sub Activity_Create(FirstTime As Boolean)
VP.Initialize("VP")
Activity.AddView(VP,0,0,100%x,100%y)
PC.Initialize
For i = 0 To 10
PC.AddPage("Page " & i)
Next
VP.PageContainer = PC
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub VP_PageCreated (Position As Int, Page As VPage)
If Page.AlreadyCreated = False Then
Page.Panel.Color = Colors.RGB(Rnd(0,256), Rnd(0,256), Rnd(0,256))
End If
End Sub
Sub VP_PageScrollStateChanged (State As Int)
If State=0 Then
Msgbox ("Now settled, but should have already fired a second earlier","Demo")
End If
End Sub