Android Question waiting for database data search

3394509365

Active Member
Licensed User
Longtime User
good evening, in my app, i have a routine that launches a search query.
I start the search by selecting a spinner's spin. "which represents the item to search for"

I tried to put B4XLoadingIndicator but it remains hidden under the spinner, and in the meantime that the search is performed, I see the spinner list.

What can I do to hide the spinner after the selection and show the loadindicator.?

Do I have to make a thread?
 

Albert Kallal

Active Member
Licensed User
Hum, ok.

So, spinner is in plain view.
User makes a selection in/from the spinner
Hide spinner
Show Loading indicator
Pull data + load up your customer view/B4xtable
Hide loading indicator
Re-display spinner

I "think" that is the flow you have? So the spinner is displayed during this process for addtional selections?

I think the above is the flow you are looking for.

So, the first question is the data pull async? (it should be).

So, I assume you drop the B4xLoader/progress thingey into the view designer.
Right click - generate Private B4XLoadingIndicator1 As B4XLoadingIndicator

Now, when you load the layout the indicatiner will start to show., so, your load up code would look somthing like this:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("MySettings")
    MyLoad
    B4XLoadingIndicator1.Hide
End Sub

You could can??? drop the B4xLoadingIndicate on the same spot as the spinner - send to back

Now, I assume some kind of click event for a spin selection occures.

So that code would be somthing like this:
B4X:
' hide spinner
MySpin.Visible = false
B4XLoadingIndicator1.Show
' pull data - MUST be async call:

        Dim sf As Object = mysql.ExecQueryAsync("mysqlWAIT", strSQLSelect ,Null)
        Wait For (sf) mysqlWAIT_QueryComplete(Success As Boolean,   Crsr2 As JdbcResultSet)
        If Success Then
            bla bla bla - load up your table/customerlistview or whatever
            Dim MyRowCount As Int = 0
            Do While Crsr2.NextRow
                  code to load up your data
                 sleep(0)     <---- you need this in the data load loop
            Loop

' done - hide progressIndicator and re-show spnner
B4XLoadingIndicator1.Hide
MySpin.Visible = true

So the key concept here is that your data pull needs to be async. That gives Mr. Android time to breath air - and it will also allow the display to hide the spinner, show the B4xLoading indicator - and of course pull the data. Without "ansyc" pull like above, then the screen updates wll NOT show until all your code is done and you not see the hide/show loading indicater.

However, the problem is that the B4XLoadingIndicator needs to breathe (run code) "while" your code runs and pulls that data (hence the sleep(0) in that loop.
If you use a standard progressbar, then you not need that sleep(0) - so you could use the circular progress bar.

Regards,
Albert D. Kallal
Edmonton, Alberta, Canada
 
Upvote 0
Top