Setting Spinner color at runtime

yttrium

Active Member
Licensed User
Longtime User
If I change a spinner's textcolor during runtime, the displayed text color doesn't change until the user selects a new item.

I've tried disabling and re-enabling to see if that refreshes the view, but it does not. What else could I try?
 

HotShoe

Well-Known Member
Licensed User
Longtime User
If I change a spinner's textcolor during runtime, the displayed text color doesn't change until the user selects a new item.

I've tried disabling and re-enabling to see if that refreshes the view, but it does not. What else could I try?

Try putting a DoEvents in right after the line where you change the color.

--- Jem
 
Upvote 0

yttrium

Active Member
Licensed User
Longtime User
Try putting a DoEvents in right after the line where you change the color.

--- Jem
Nope, didn't work. I've also now tried invalidating the spinner after changing the color - and somehow, that doesn't work either. Even changing the selected index to something else and then back again doesn't fix it - only if the USER forces it to a different item does it refresh.
 
Last edited:
Upvote 0

yttrium

Active Member
Licensed User
Longtime User
Bump?
 
Upvote 0

yttrium

Active Member
Licensed User
Longtime User
You will need to recreate the spinner if you change the color.

Really? There is absolutely no workaround for this?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Spinner (like ListView) reuses the views when it shows items. So instead of creating a view for each item it only creates a view for each visible item and then reuses these views.

Changing the text color at runtime will not change the text color of existing views. So you will need to recreate the spinner. Note that it should be a very quick operation to rebuild the spinner.
 
Upvote 0

yttrium

Active Member
Licensed User
Longtime User
Spinner (like ListView) reuses the views when it shows items. So instead of creating a view for each item it only creates a view for each visible item and then reuses these views.

Changing the text color at runtime will not change the text color of existing views. So you will need to recreate the spinner. Note that it should be a very quick operation to rebuild the spinner.

I'm just confused why invalidating a view doesn't refresh it.
 
Upvote 0

yttrium

Active Member
Licensed User
Longtime User
Spinner (like ListView) reuses the views when it shows items. So instead of creating a view for each item it only creates a view for each visible item and then reuses these views.

Changing the text color at runtime will not change the text color of existing views. So you will need to recreate the spinner. Note that it should be a very quick operation to rebuild the spinner.

How can I draw a new view inside of a specific AHViewPager page? Is drawing a new view the only way to reload the Spinner?
 
Upvote 0

yttrium

Active Member
Licensed User
Longtime User
I'm not really familiar with AHViewPager however creating a new view is usually quite simple. You just need to call Spinner1.RemoveView to remove the view from its parent. Create the new view and add it to its parent.
The issue at this point isn't removing the view, it's adding it. AHViewPager uses panels to display views, and moves the panels. However, while you can use AHViewContainer.GetPageObject to reference the panel, you cannot perform an operation FROM that panel (AddView) using that method.

EDIT: By moving the panel creation to a separate line and creating a variable for it BEFORE adding it to the AHViewContainer, I can reference it and access its AddView method.

However, removing the view and then re-adding it does not refresh the color, either. Do you mean recreating the spinner, period? As in, defining a new one?

EDIT2: I think I finally get what you mean - removing all fields and adding them again. Let me play with that.
 
Last edited:
Upvote 0

yttrium

Active Member
Licensed User
Longtime User
You should recreate the spinner.

Recording the current position, clearing all items, and then re-adding those items and setting the position back does refresh the spinner without respawning it.
 
Upvote 0

hypergreatthing

Member
Licensed User
Longtime User
Recording the current position, clearing all items, and then re-adding those items and setting the position back does refresh the spinner without respawning it.
B4X:
Sub refreshSpinner(spin As Spinner)
    Dim arraytemp(spin.Size) As String, selectedIndex As Int
    For x=0 To spin.Size-1
        arraytemp(x)=spin.GetItem(x)
    Next
    selectedIndex=spin.selectedIndex
    spin.Clear
    For x = 0 To arraytemp.Length-1
        spin.Add(arraytemp(x))
    Next
    spin.selectedIndex=selectedIndex
End Sub
Execute that after a textcolor and it will change the text color. I wish there was an easier way to just say "redraw".
 
Upvote 0
Top