B4J Question Color Picker Event is fired in an endless Loop

nobbi59

Active Member
Licensed User
Longtime User
hey B4J experts,

I am using a color picker in my B4J UI Application. But I have a little Problem:

The _ValueChanged event is fired multiple times in an endless loop. The ColorPicker is added via code, not with the designer.

Is this a known issue or not?

Best regards.
 

stevel05

Expert
Licensed User
Longtime User
No it works as expected here, how have you added it to your code?
 
Upvote 0

nobbi59

Active Member
Licensed User
Longtime User
Thanks for your Answer,

I add it to a pane in a loop. But I remove the view after a color is selected and the re-add a new view with the same eventname, may this be a reason?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Not directly, can you post the code?
 
Upvote 0

nobbi59

Active Member
Licensed User
Longtime User
This is how I add the Color Picker

B4X:
Dim addnode As Node
   
    If typ = "color" Then
       Dim cp As ColorPicker
       cp.Initialize("color_picker")
       cp.SelectedColor = value
       cp.Tag = setid
       addnode = cp
    End If
    If typ = "check" Then
       Dim cb As CheckBox
       cb.Initialize("checkbox")
       cb.Checked = value
       cb.Tag = setid
       addnode = cb
    End If
   
    Dim tit As Label
    tit.Initialize("tit")
    tit.Text = title
   
    Dim pnl_split As Pane
    pnl_split.Initialize("splitter")
    CSSUtils.SetBackgroundColor(pnl_split,fx.Colors.LightGray)
   
    parent.AddNode(tit,4dip,ynow,parent.PrefWidth/2-4dip,30dip)
    parent.AddNode(addnode,parent.PrefWidth/2 + 10dip,ynow+2dip,parent.PrefWidth/2 -20dip,26dip)
    parent.AddNode(pnl_split,0,ynow+32dip,parent.PrefWidth,1dip)


And I remove all the views from the "parent" Pane and then Call this code again
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Is the routine called just once before the views are removed?
 
Upvote 0

nobbi59

Active Member
Licensed User
Longtime User
I found ot where the problem is. I set the SelectedColor Property and as result of this, the event is fired again. So this becomes a loop, because the above code is called when the event is fired.

Is there any way to prevent the event from beeing executed? So can I checked if the vent comes from the UI or from code?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Why do you set the colorproperty of the colorPicker from the colorpicker changed event?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You can set a global boolean variable to true when you set the value in code, when the changed sub is called with it set to true, set it to false and return without doing anything.
 
Upvote 0

nobbi59

Active Member
Licensed User
Longtime User
Good Idea, will try that. but ill try to improve the whole code to not be depending on this.

Thanks for helping me!
 
Upvote 0
Top