ScrollPosition of ScrollView in CustomDialog

COBRASoft

Active Member
Licensed User
Longtime User
Hi,

I have a problem setting the ScrollPosition of a ScrollView in a CustomDialog. The Dialog shows with the scrollview, but the position hasn't changed like it should. Any ideas?

Greetings,
Sigurd
 

ZenWhisk

Member
Licensed User
Longtime User
I also have this problem, I have a custom dialog containing a scroll view of times (as labels in the view) and I want to start it ready scrolled to the current value.

If I scroll to position when clicking on a label on the scrollview on the dialog, it works, but not at the start.
 
Upvote 0

ZenWhisk

Member
Licensed User
Longtime User
Thanks for the very fast response ! I was just trying to remember how to post source properly !
I have an activity with a button1 to test my dialog

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
    Dim Button1 As Button
    Dim lblDate As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")

    Activity.Color=Colors.white
    lblDate.Initialize("lblDate")
    Activity.AddView(lblDate,0,0,100%x,100dip)
    Button1.Initialize("Button1")
    Button1.Text="Test Time Dialog"
    Activity.AddView(Button1,0,200dip,100%x,100dip)
  
End Sub

Sub Button1_Click
    Dim T As TimePicker
    T.Initialize(Me,"timepick")
    T.ShowTimeDialog
End Sub

Here is the dialog class, when I touch a label, it scrolls to the top nicely, but I cannot think of anyway to get it to start at say 12 o'clock

B4X:
'Class module
Sub Class_Globals
    Dim lblDt As Label
    'Dim fontExistence As Typeface     = Typeface.LoadFromAssets("Existence-Light.otf")

    Dim cd As CustomDialog  
    Dim myfont As Typeface

    Public m_Reply As String
    Dim sv As ScrollView
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize (Target As Object, EventName As String)

End Sub

Sub lbl_click
    Dim lbl As Label
    lbl=Sender
    lblDt.Text=lbl.Text

    'This scrollposition works well
    sv.ScrollPosition=lbl.top
End Sub

public Sub ShowTimeDialog
    myfont=Typeface.DEFAULT

    Dim pnl As Panel
    pnl.Initialize("pnl")
    cd.AddView(pnl, 0, 0%y, 80%x,80%y)
  

    lblDt.Initialize("lblDt")
    lblDt.TextSize=48
    lblDt.Color=Colors.RGB(0x21,0xC7,0x9A)
    lblDt.TextColor=Colors.white
    lblDt.Gravity=Gravity.CENTER
    lblDt.Typeface=myfont
  
    pnl.AddView(lblDt,0,0,pnl.Width,70dip)

    Dim i As Int
    Dim heightOfTimeLabel As Int=70dip

    sv.Initialize(200%y)
    pnl.AddView(sv,0,lblDt.Height,pnl.Width,pnl.Height-lblDt.Height)
    Dim w As Int =pnl.Width/2
    For i = 0 To 23
        Dim lbl As Label        'Round Hour label
        lbl.Initialize("lbl")
        lbl.text = i & ":00"
        lbl.TextSize = 48
        lbl.Gravity=Gravity.RIGHT
        lbl.Typeface=myfont
        sv.Panel.AddView(lbl,0,i*heightOfTimeLabel,w,heightOfTimeLabel)
      
        Dim lbl2 As Label        'Half hour label
        lbl2.Initialize("lbl")
        lbl2.text = i & ":30"
        lbl2.TextSize = 48
        lbl2.Gravity = Gravity.RIGHT
        lbl2.TextColor = Colors.RGB(220,220,220)
        lbl2.Typeface = myfont
        sv.Panel.AddView(lbl2,w,i*heightOfTimeLabel,w,heightOfTimeLabel)
    Next
    sv.Panel.Height = 24*heightOfTimeLabel

    'I want to scroll to this position but it does not work
    'here is perhaps too early
    sv.ScrollPosition=12*heightOfTimeLabel  
    DoEvents

    cd.Show("Start Time",  "OK",  "", "" , Null)
    'but it is too late here

End Sub
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Probably CustomDialog needs an internal refresh (Invalidate + DoEvents).

You could create your own Dialog (two panels, the "external" one - parent - 100%x, 100%y and transparent, the internal - child - will contain all your views).
 
Upvote 0

ZenWhisk

Member
Licensed User
Longtime User
Invalidate + doevents did not help when using custom dialog, but worked well when I implemented your idea of a 'pseudo dialog'. Strangely I had to do it both before and after setting the scroll position. Case Solved, many thanks !
 
Upvote 0
Top