B4J Question Using B4XLoadingIndicator with B4XTable and B4XPages

aeric

Expert
Licensed User
Longtime User
What is the recommended way to show and hide B4XLoadingIndicator when a B4XPage finished loading and reload B4XTable?
Do I need to use Sleep(0) before B4XLoadingIndicator.Show and B4XLoadingIndicator.Hide ?
 

aeric

Expert
Licensed User
Longtime User
Is this correct?

B4X:
LoadingIndicator.Show
Sleep(1000)

Dim Columns As List
Columns.Initialize
Columns.Add(Map1)
Columns.Add(Map2)

B4XTable1.Clear
AddColumns(B4XTable1, Columns)

Dim Data As List
Data.Initialize
Dim Query1 As String = "SELECT..."
Dim RS1 As ResultSet = DB.ExecQuery(Query1)
Do While RS1.NextRow
    Data.Add(Array("col1", "col2"))
Loop
RS1.Close

Wait For (B4XTable1.SetData(Data)) Complete (Unused As Boolean)
B4XTable1.Refresh
LoadingIndicator.Hide
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Not exactly. I guess that the slow part is the retrieval from the db. If I'm correct then you need to switch to the async SQL method.
Actually I don't mean the loading is slow. I had expected it but I just want to let the users see or experience that it is loading so it doesn't seem hang.
My question is what is the correct place to put the indicator.Show and Hide it?
I am now putting it at 2 places; 1 inside B4XPage_Created after loading the layout and 1 inside LoadData where the data is read. Because I have another button to refresh the data. So far it seems achieve what I am looking for. Just not sure how other are achieving this or there is a better way.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
1. The sleep duration is too long.
2. Test it in release mode.
3. Add some measurements to understand the timing of each step.
I have changed it to Sleep(0), but putting a longer sleep (like 500ms) and show a short animation won't harm to end user, I think. Using SQLite is too fast LOL.

I have removed the unnecessary .Refresh after SetData as you suggested.
Only left them at after .VisibleColumns.RemoveAt() and .sql1.ExecNonQuery2("UPDATE data SET ...")

My B4XPage_Created has a lot of localization, Theming, Styling which may slow down the start up of the page.

Beside the reading of database, another thing that I suspect may slow down the B4XTable is the create buttons of Edit column.

By the way, it is not really slow as I said. It just like 0.5 or less than 1 second.
Will check again on Release mode.

Thanks Erel.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Consider this scenario happen in the office.
A user or boss ask the developer to add a button to refresh the data showing on the table.

Boss: Can you add a refresh button?
Me: Yes, boss. Added. Try it now.
Boss clicked the button.
Boss: Not working!
Me: It is working, boss. It just too fast and the data has not changed.
Me adding the loading indicator with sleep.
Me: Boss, try it now.
Boss test it again.
Boss: Now it is working!
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Another concept I had thought before is calculate if a process is taking too long.
Let say a process is taking more than 3 seconds, it is considered as long process, then only show the indicator.
Not sure anyone will implement such approach, maybe in other scenario, but not to use in B4XTable?
 
Upvote 0
Top