Android Question Problem with ScrollView_ScrollChanged

susu

Well-Known Member
Licensed User
Longtime User
Hi all,

I used ScrollChanged event to know when the ScrollView reachs the end but it seems ScrollChanged fired multiple times (or my code is wrong?).

B4X:
Sub sv_ScrollChanged(Position As Int)
        If Position + sv.Height >= sv.Panel.Height Then
            sv.ScrollPosition = Position - 100dip
            numberoflastscroll = numberoflastscroll + 1
            Msgbox(numberoflastscroll, "Number of last scroll action")
        End If
End Sub

I expected the message box will appears one by one after each time I scroll to the end of scroll view. But now it continually count "2", "3", "4"... when I scroll to the end of scroll view 1 time.

Please check the exported project to see the problem. Thank you.
 

Attachments

  • scrollchanged.zip
    5.9 KB · Views: 257

Erel

B4X founder
Staff member
Licensed User
Longtime User
The scroll changed events are sent to the message queue and then they are processed. This means that multiple events have already been sent when you process the first event. I'm not sure what you are trying to do. However you should probably change your code to check for two levels. First that the position is higher than the max value and then that it is lower than max - delta. Only then you should allow the next "scroll to bottom" event.

(such a solution is sometimes named hysteresis)
 
Upvote 0

uhzeg

Member
Licensed User
Longtime User
susu,

I have the same behaviour and I was not able to fix it even with Erel's answer.
Have you been able, and if yes, could you please paste your new
B4X:
Sub sv_ScrollChanged(Position As Int)
?
Thanks in advance
 
Upvote 0
Top