Android Question Can't get Progress Bar to Show

Tim Chapman

Active Member
Licensed User
Longtime User
I got the progress bar from here: https://www.b4x.com/android/forum/threads/simple-progress-bar.95324/
I made a small program to test it which is attached. In that code, the progress bar is on a panel in the designer.
In my code it is on the activity just like the table is. This was done in the designer.

At the beginning of the sub, I make the table invisible and make the parts for the progress bar visible. These are in my main.bal file.
Throughout the sub, I update the progress and show the progress bar.
At the end of the sub I make the table visible and make the parts for the progress bar invisible.

The table never becomes invisible and the progress bar parts never become visible.

Project is attached if you want to see the rest.
To make it work fully, open the todo list.xls spreadsheet in the files folder. Go to the Contexts sheet. Change the latitude and longitude of Home to match your current position.
Save it and Run the code.
If you want to try the LeaveHere button on the menu, select Semi as your destination.
One item will show in the table.

LoadArray Sub:
Sub LoadArrays
    Log("LoadArrays sub start")
    Private row As Long
    Private workbook1 As ReadableWorkbook
    Private TodoSheet As ReadableSheet
    
    table1.Visible = False
    pnlBar.Visible = True
    pnlValue.Visible = True
    lblMessage.Visible = True
    lblMessage.Text = "Loading.  Please wait."

    workbook1.Initialize(Starter.Dir, Starter.FileName)
    'workbook1.Initialize(File.DirAssets, Starter.FileName)    'klaus
    TodoSheet = workbook1.GetSheet(0)
    Starter.TodoList.Initialize

    'Get the header row.
    row = 0
    
    HeaderRow(0) = TodoSheet.GetCellValue(0,row)
    HeaderRow(1) = TodoSheet.GetCellValue(1,row)
    HeaderRow(2) = TodoSheet.GetCellValue(2,row)
    HeaderRow(3) = TodoSheet.GetCellValue(5,row)
    HeaderRow(4) = TodoSheet.GetCellValue(6,row)
    HeaderRow(5) = TodoSheet.GetCellValue(9,row)
    HeaderRow(6) = TodoSheet.GetCellValue(17,row)
        
    'Load the main sheet of the spreadsheet into a list of type Todo.  See here for an example under SortType: https://www.b4x.com/android/help/collections.html#list_sorttype
    'Log(TodoSheet.RowsCount)
    
    For row = 1 To TodoSheet.RowsCount - 1
        If IsNumber(TodoSheet.GetCellValue(2,row)) Then
            If TodoSheet.GetCellValue(2,row) > 0 And TodoSheet.GetCellValue(2,row) < 5 Then
                Private TempTodo As Todo
                TempTodo.Initialize
                TempTodo.ID = TodoSheet.GetCellValue(0,row)
                TempTodo.Name = TodoSheet.GetCellValue(1,row)
                TempTodo.Status = TodoSheet.GetCellValue(2,row)
                TempTodo.Context = TodoSheet.GetCellValue(5,row)
                TempTodo.Category = TodoSheet.GetCellValue(6,row)
                TempTodo.Priority = TodoSheet.GetCellValue(9,row)
                TempTodo.Note = TodoSheet.GetCellValue(17,row)
                Starter.TodoList.Add(TempTodo)
                ExitFlag = 0
                ProgressValue = row/TodoSheet.RowsCount*90
                pnlValue.Width = ProgressValue/100 * pnlBar.Width
            End If
        Else
            ExitFlag = 1 'Found the first blank cell.
        End If
        If ExitFlag = 1 Then Exit
    Next
    'Log("Todo List Size = "&TodoList.Size)

'    For row = 0 To TodoList.Size-1
'        Log("Todo " & row & " = " & TodoList.Get(row))
'    Next

    'Load Statuses
    Log("Loading Statuses from spreadsheet")
    Private StatusSheet As ReadableSheet
    StatusSheet = workbook1.GetSheet(7)
    For row = 0 To StatusSheet.RowsCount - 1
        For column = 0 To 1
            Statuses(row,column) = StatusSheet.GetCellValue(column, row)
            'Log("Status("&row&","&column&" = "&Statuses(row,column))
        Next
        'Log("...")
    Next
    ProgressValue = 92
    pnlValue.Width = ProgressValue/100 * pnlBar.Width
    
    'Load Contexts (Locations for the Tasks)
    
    'Context() columns:
    '0 is Context Name.
    '1 is Context Number.
    '2 is Latitude.
    '3 is Longitude.
    '4 is Distance.
    '5 will be whether or not the phone is within the Distance (#4) of the context.
    '    Column 5 is populated in the Tracker.CheckDistance sub.
    '6 will be the contexts the user wants to see the todos for.
    '    Column 6 will be populated in the ContextCheck sub below.

    Private ContextSheet As ReadableSheet
    ContextSheet = workbook1.GetSheet(2)
    LastContext = ContextSheet.RowsCount - 1
    
    '         col,row
    'Cell A0 is 0,0
    'Cell B0 is GetCellValue(col,row) 1,0.
    'Cell A1 is 0,1
    'Cell B1 is 1,1
    
    Dim rowa As Byte
    Log("Loading Contexts from spreadsheet")
    'Log("Last Context = "&LastContext)
    'This below is confusing.  The spreadsheet rows start at 0.
    'The Contexts start at 1 (See the Contexts sheet.)
    For row = 0 To LastContext 'col,row  Spreadsheet cell A1 is 0,0.
        rowa = row+1 'Fore the Contexts Counter.
        Contexts(rowa,0) = ContextSheet.GetCellValue(0,row) 'Name
        'Log("Context Name = ("&rowa&","&0&" = "&Contexts(rowa,0))
        
        Contexts(rowa,1) = ContextSheet.GetCellValue(1,row) 'Number
        'Log("Context Number = ("&rowa&","&1&" = "&Contexts(rowa,1))

        Contexts(rowa,2) = ContextSheet.GetCellValue(2,row) 'Latitude
        'Log("Context Latitude = ("&rowa&","&2&" = "&Contexts(rowa,2))
        
        Contexts(rowa,3) = ContextSheet.GetCellValue(3,row) 'Longitude
        'Log("Context Longitude = ("&rowa&","&3&" = "&Contexts(rowa,3))
        
        Contexts(rowa,4) = ContextSheet.GetCellValue(4,row) 'Distance
        'Log("Context Distance = ("&rowa&","&4&" = "&Contexts(rowa,4))
        'Log("...")
    Next
    
    LastContext = LastContext + 1
    
    ProgressValue = 95
    pnlValue.Width = ProgressValue/100 * pnlBar.Width
    
    'Load Categories
    Log("Loading Categories from spreadsheet")
    Private CategoriesSheet As ReadableSheet
    CategoriesSheet = workbook1.GetSheet(1)
    For row = 1 To CategoriesSheet.RowsCount - 1 'Ignoring the top row.  It is a header row.
        For column = 0 To 1
            Categories(row,column) = CategoriesSheet.GetCellValue(column, row)
            'Log("Categories("&row&","&column&") = "&Categories(row,column))
        Next
        'Log("...")
    Next
    ProgressValue = 99
    pnlValue.Width = ProgressValue/100 * pnlBar.Width
    
    table1.Visible = True
    pnlBar.Visible = False
    pnlValue.Visible = False
    lblMessage.Visible = False
    Log("LoadArrays sub done")
End Sub
 

Attachments

  • Simple Progress Bar.zip
    8.6 KB · Views: 110
  • TimTodo.zip
    253.7 KB · Views: 104

Brian Michael

Active Member
Licensed User
Hello! Try Using Sleep(0) by steps, maybe helps with multiple taks.
 
Upvote 0

Tim Chapman

Active Member
Licensed User
Longtime User
Hi Brian,
Thank you for the reply, but adding sleep(0) in the sub that has the progress bar made it resumable. Then the code bombs.
I have forced resumable subs not to be resumable so I can have predictable handling of the code.
I use the approach spelled out here in order to do that:

So, if Sleep(0) is required for the progress bar to work, I guess I won't have one. Right now my code is executing fast enough that it is not needed. But, for some reason it can change and go very slowly.
 
Upvote 0
Top