Android Question using progress bar while fetching json records

Makumbi

Well-Known Member
Licensed User
Please help me implement a progress bar for this code so that the user can know that their is a pending activity
Which counts from 0 to 100
thanks advance

B4X:
Dim jt As HttpJob
        jt.Initialize("", Me)
        jt.Download("http://kccug.com/KabojjaApp/HandlerVBacademia.ashx")
        'jt.GetRequest.Timeout = 1000 ' 10 seconds
        Wait For (jt) JobDone(jt As HttpJob)
        If jt.Success Then ' if job is success (http status code 200)
            Dim RetVal As String
            RetVal = jt.GetString
            Log(RetVal)
            If jt.GetString = "[]" Then
                'MsgboxAsync("No Records to Upload Yet for: " & CustID ,"SMIS")
                Return
            Else
                Dim jp As JSONParser
                jp.Initialize(jt.GetString)
                'Log(jp) ' will pr
                Log($"Token(${jp})"$)
                Dim quotdt As List = jp.NextArray
                For Each quotd As Map In quotdt
                    Log("Account: " & quotd.Get("Account"))
                    Log("Grade: " & quotd.Get("Grade"))
                    Log("Mids: " & quotd.Get("Mid"))
                    Log("Ends: " & quotd.Get("Ends"))
                    Log("Stream: " & quotd.Get("Stream"))
                    Log("Names: " & quotd.Get("Names"))
                    Log("Class: " & quotd.Get("class"))
                    Log("Term: " & quotd.Get("Term"))
                    Log("Subject: " & quotd.Get("Subject"))
                    Log("Total: " & quotd.Get("Total"))
                    Log("atk: " & quotd.Get("autofield"))
                                    
                    'If quotd.Get("Account")=actsd Then
                        
                        Starter.SQL1.ExecNonQuery("INSERT INTO Academics VALUES('" & quotd.Get("Names") & "','" & quotd.Get("class") & "','" & quotd.Get("Stream") & "','" & quotd.Get("Subject")  & "','" & quotd.Get("Total") & "','" & quotd.Get("Grade") & "','" & quotd.Get("Mid")  & "','" & quotd.Get("Ends") & "','" & quotd.Get("Term") & "','" & quotd.Get("Years") & "','" & quotd.Get("atk") & "')")
                    'End If
                Next
        

                Return
                jt.Release
            
            End If
    
        Else
        
            
            'Msgbox("Error Connecting to the Server Please Check Your Internet Connection","Server Error")
        End If
    'Next
 

DonManfred

Expert
Licensed User
Longtime User
Which counts from 0 to 100
there is no such thing in httpjobs!

You start the job and it returns when the webservice answers.

You can show a indeterminate progress while the job is running if you want.
Learn the language and play with the views available.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
the request,the list count (quotdt) or the data insert can be used as progress.
after the http request you can calculate the max progress count and then just add one to the progress indicator.
a status info is also good.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Test
   
    Dim i As Int = 0
    Dim maximal As Int = 452
   
    For i=0 To maximal  
        Log(i)
        ProgressBar1.Progress = (i / maximal)*100
        Sleep(25)
    Next
       
End Sub
 
Upvote 0
Top