scrollview event not working in Beta?

derez

Expert
Licensed User
Longtime User
Hi
I wrote this code as a class for wheelview, following the example of the edittext.
For some reason the event sv_ScrollChanged is not firing.
Can you please check. It seems that everything works except this (the wheel is drawn and scrolls but not adjust to the center of value because the timer is not launched).

B4X:
'Class module
Sub Class_Globals
Dim Wwheelstep, newposition,WHeight,  textsize, lblgravity, delay  As Int
Dim sv As ScrollView
Dim Wmodule As Object
Dim lbw As Label
Dim textcolor, lblcolor As Long
Dim values(2), WEventName As String 
Dim tmr As Timer
Dim Wcyclic  As Boolean
        
End Sub

'Initializes the object. You can add parameters to this method if needed.
Sub Initialize(module As Object, wheelstep As Int, First As Int, Last As Int, cyclic As Boolean ,  EventName As String)

Dim n As Int
Wmodule = module

textsize = 24
delay = 700 
textcolor = Colors.Black
lblcolor = Colors.WHITE
lblgravity =  Gravity.CENTER
Wwheelstep = wheelstep
WEventName = EventName

If cyclic Then
   n = Last - First + 3
   Dim values(n) As String
   values(0) = Last
   For i = 1 To n-1   
      values(i) = First + i-1
   Next
   values(n-1) = First
Else
   n = Last - First + 1 
   Dim values(n) As String
   For i = 0 To n-1   
      values(i) = First + i
   Next
End If
init
End Sub

Sub init
   Dim n As Int
   n = values.length 
   WHeight = (n + 2)* Wwheelstep 
   sv.Initialize(WHeight)
   sv.panel.Initialize("")
   sv.Enabled = True
   sv.panel.Color = lblcolor
   putlabels( n) 
   tmr.Initialize("tmr", delay)
   tmr.Enabled = False
   '***********************************************
   ' just for testing:
   
'   sv_ScrollChanged( 343)
'   sv.FullScroll(True)
   sv.ScrollPosition = 345
   DoEvents
   DoEvents
   DoEvents
   'tmr.Enabled = True
End Sub

Sub putlabels(n As Int)
For i = 0 To n-1
   lbw.Initialize("")
   lbw.Text = values(i) 
   lbw.textcolor = textcolor
   lbw.Color = lblcolor
   lbw.textsize = textsize
   lbw.Gravity = lblgravity
   sv.panel.AddView(lbw , 0, Wwheelstep*(i +1) ,sv.panel.Width, Wwheelstep)
Next
End Sub

Sub AsView As View
    Return sv
End Sub

Sub sv_ScrollChanged(Position As Int)
Dim y As Double
y = Position
Log("scroll")
If Wcyclic Then
   If Position > WHeight - 3.4 * Wwheelstep  Then
       newposition =  Wwheelstep  
      sv.ScrollPosition = newposition
   Else If Position <  0.6 * Wwheelstep   Then
       newposition = WHeight - 3.6 * Wwheelstep
      sv.ScrollPosition = newposition
   Else 
      y = Position
      newposition = Wwheelstep * Floor(y/Wwheelstep + 0.5)
   End If
Else
   newposition = Wwheelstep * Floor(y/Wwheelstep + 0.5) 
End If

If  SubExists( Wmodule, WEventName & "_ScrollChanged") Then
   CallSub2(Wmodule, WEventName  & "_ScrollChanged", Position)            
End If            
tmr.Enabled = True
End Sub

Sub tmr_tick
sv.ScrollPosition = newposition
tmr.Enabled =  False
If SubExists(Wmodule, WEventName & "_Roll") Then
  CallSub2(Wmodule,WEventName & "_Roll",values(newposition/Wwheelstep))   
End If
End Sub

The main is doing this:
B4X:
sub init_wheel
wc1.Initialize("main",svstep,1,31,True,"wc1")
Activity.AddView(wc1.AsView,100dip,170dip,40dip,svstep*3)
End Sub

Sub wc1_Roll(stepval As String)
Log(stepval)
End Sub
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Just looking quickly at it, it looks as though you haven't passed the event name to the SV, try using sv.initialize2(height,eventname) in the init sub.

Hope this helps.
 
Upvote 0
Top