Android Question Progressshowdialog where to show

raphipps2002

Active Member
Licensed User
Longtime User
I want to load a progressshowdialog as the activity is started, then the 'sub showall' is called which loads a sql DB and displays two columns of labels with text and numbers. This sub might take 3-5 seconds.

But the dialog doesnt show until the sub is completed...obviously too late!

How should the dialog be used to load before the sub showall.

I tried putting it in the showall sub or as below in the Activity.create...neither worked



B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
   
    Activity.LoadLayout("LYShowTrn")
    Activity.Title = "All account transactions"
   
   
    ProgressDialogShow("...loading")
  
    Dim p As Phone
    p.SetScreenOrientation(0)
    lblOBtot.Text = Main.BankOpeningBalanceFromSystem

    ShowAll
   
    ProgressDialogHide
   
   
   
End Sub
 

raphipps2002

Active Member
Licensed User
Longtime User
Thanks. I tried that and it certainly displayed the ...loading dialog text but it looked clumsy.
Seemed to flick between 1) Portrait with my buttons & labels 2) a blank scrollview 3) the correct format in landscape which is landscape and all the labels

As it if was drawing in portrait, then re-displaying the view in landscape as I wanted

in fact the little spinning icon spun but once again as the sub was called and the sql db is being loaded it froze until the whole view was drawn (scrollview with a few columns on buttons and labels)

Just in principal, if

1) a progressdialog is called and then;
2) a sub is called with some loop that might take a few seconds then

surely, I thought, as the cursor is being populated with the sql query there seems to be two delays

one as the cursor is populated, and two in the same sub as the scrollview is drawn with dynamic buttons and labels in a scrolling table with the cursor values; maybe taking 3-4 seconds.

I tried putting the progressdialog in a timer interrupt event with value 1ms in an attempt to force it to redraw...but that failed too and also an animate spinning label instead. Both however, paused as the the table is drawn. and/or cursor populated

of course what i want is a spinning wheel as both things are happening

so I run out of ideas Her is my Sub ...

B4X:
Sub ShowAll
  
    Main.sql1.Initialize(File.DirDefaultExternal,Main.FileDB,False)
    Dim cursor1 As Cursor = Main.sql1.ExecQuery("Select * from data order by datetick")
    Dim count As Int = cursor1.RowCount
  
    DateTime.DateFormat = "dd/MM/yyyy"
  
    Dim btnH As Int = PerXToCurrent(5)
    Dim toppos As Int = PerYToCurrent(1)
    Dim gap As Double = PerYToCurrent(0.25)

    scrv1.Panel.Height = (count * btnH + (count * gap))
  
    Dim TOut As Double = 0
    Dim TIn As Double = 0
  
    For i = 0 To count-1


        cursor1.position  = i
      
        Dim DT As Long = cursor1.GetLong("Datetick")
        Dim desc As String = cursor1.GetString("desc")
        Dim AOut As Double = cursor1.GetDouble("Amountout")
        Dim AIn As Double = cursor1.GetDouble("Amountin")  
      
        TOut = TOut + AOut
        TIn = TIn + AIn
      
        Dim b1 As Button
        Dim b2 As Button
        Dim b3 As Button
        Dim b4 As Button
        b1.Initialize("")
        b2.Initialize("PressDesc")
        b3.Initialize("")
        b4.Initialize("")
  
        b1.Color = Colors.Black
        b1.TextColor = Colors.White
  
        b1.TextSize = ts1
        b2.TextSize = ts1
        b3.TextSize = ts1
        b4.TextSize = ts1
        b1.Gravity = Gravity.LEFT
        b2.Gravity = Gravity.LEFT
        b3.Gravity = Gravity.right
        b4.Gravity = Gravity.right
      
        b1.Text = DateTime.Date(DT)
        b2.Text = desc
        b2.Tag = i

      
        If AOut <> 0 Then
            b3.Text = DP(AOut)
        Else
            b3.Text = ""
        End If
      
        If AIn  <> 0 Then
            b4.Text = DP(AIn)
        Else
            b4.Text = ""
        End If
      
      
        scrv1.Panel.AddView(b1,1%x,toppos,20%x,btnH)
        scrv1.Panel.AddView(b2,21%x,toppos,40%x,btnH)
        scrv1.Panel.AddView(b3,62%x,toppos,17%x,btnH)
        scrv1.Panel.AddView(b4,79%x,toppos,17%x,btnH)
      

      
        toppos = toppos + btnH + gap      
      
      
    Next
  
  
    cursor1.Close
  
    btnOut.Text = DP(TOut)
    btnIN.Text = DP(TIn)
  
    Cbal = Main.BankOpeningBalanceFromSystem + TOut + TIn
  
    lblCBal.Text = DP(Cbal)
  
  
  
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…