B4J Question MainForm - Force redraw/update

Jim Brown

Active Member
Licensed User
Longtime User
Is there a way to force the MainForm to update its components?

My basic problem is:

1) User selects a menu action which leads to an intensive routine
2) I want to update a status textfield before the routine runs - E.g, "Working ..."

The issue is, although I call MyTextField.Text="Working .." before the intensive routine the actual update to the text field does not happen until the menu action sub is completed.

I need something like:

B4X:
Sub menu_DoStuff_Action
   MyTextField.Text="Working .."
   MainForm.Update  ' <--------------- THIS
   Do_Big_Task_Here
   MyTextField.Text="Done"
End Sub

Thanks
 

stevel05

Expert
Licensed User
Longtime User
You could try using CallSubDelayed to call the big sub, you would need a callback sub which is called when the routine finishes which in your example would update the MyTextField.Text.
 
Upvote 0

Jim Brown

Active Member
Licensed User
Longtime User
Thanks Steve,
I will look at the CallSubDelayed option.

Hi Erel,
The task is a sprite cutter, which scans through an image for individual sprites. Now, the bigger the sprite sheet image the longer the process will take.
spritecutter_zpseace2ad5.png


The only thing is, the application looks like it has frozen for 1-2 seconds until the routine has completed (the sub ends).
Everything is happening inside the Sub menu_DoStuff_Action ... End Sub
I actually want to show a spinning progress bar and update the text box. Although I am taking care of these before running the loop they never get updated.

Perhaps if possible an .Invalidate method could be added to force the UI elements in question to refresh?

B4X:
MyTextField.Text="Working .."
MyProgress.Visible=True
MyTextField.Invalidate
MyProgress.Invalidate
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Try putting DoEvents calls within the sub. That should allow the Gui to continue. The other option is to lock the Gui, with a panel that has it's click's consumed and run the process in a thread, which will allow the Gui to maintain the progress bar if it's set as indeterminate..
 
Upvote 0
Top