Android Question DesignerArgs with CustomView

Cadenzo

Active Member
Licensed User
Longtime User
How can I get a CustomView from the DesignerArgs? Here I read, that it is in the .Tag of B4XView. But the code below does not work (java.lang.RuntimeException: Field: ba not found in: android.widget.TextView)
B4X:
'Parameters: PrimaryColorID, SecondaryColorID, View(s)
Private Sub SetSwiftbuttonColor(DesignerArgs As DesignerArgs)
    If DesignerArgs.FirstRun Then
        Dim iPrimary As Int = GetColor(DesignerArgs.Arguments.Get(0))
        Dim iSecondary As Int = GetColor(DesignerArgs.Arguments.Get(1))
        For i = 2 To DesignerArgs.Arguments.Size - 1
            Dim v As B4XView = DesignerArgs.GetViewFromArgs(i)
            Dim sbtn As SwiftButton = v.Tag 'tag empty?
            sbtn.SetColors(iPrimary, iSecondary)
        Next
    End If
End Sub

'in DesignedScript:
MyDDD.SetSwiftbuttonColor(4, 5, SwiftButton1)
 
Solution
Add sleep in sub SetSwiftbuttonColor, it will work,B4j is not required.
B4X:
Private Sub SetSwiftbuttonColor(DesignerArgs As DesignerArgs)
    Sleep(10)
    Dim iPrimary As Int = GetColor(DesignerArgs.Arguments.Get(0))
    Dim iSecondary As Int = GetColor(DesignerArgs.Arguments.Get(1))
    For i = 2 To DesignerArgs.Arguments.Size - 1
        Dim v As B4XView = DesignerArgs.GetViewFromArgs(i)
        If v.tag Is SwiftButton Then
            Dim sbtn As SwiftButton = v.Tag
            sbtn.SetColors(iPrimary, iSecondary)
        End If
    Next
End Sub

teddybear

Well-Known Member
Licensed User
Try this code
B4X:
Private Sub SetSwiftbuttonColor(DesignerArgs As DesignerArgs) 
        Dim iPrimary As Int = GetColor(DesignerArgs.Arguments.Get(0))
        Dim iSecondary As Int = GetColor(DesignerArgs.Arguments.Get(1))
        For i = 2 To DesignerArgs.Arguments.Size - 1
            Dim v As B4XView = DesignerArgs.GetViewFromArgs(i)
            If v.tag Is SwiftButton Then
                Dim sbtn As SwiftButton = v.Tag
                sbtn.SetColors(iPrimary, iSecondary)
            End If
        Next
End Sub
 
Upvote 0

teddybear

Well-Known Member
Licensed User
The designer script is same as post #1
Output
B4X:
anywheresoftware.b4a.BALayout
android.widget.TextView
 
Last edited:
Upvote 0

teddybear

Well-Known Member
Licensed User
Add sleep in sub SetSwiftbuttonColor, it will work,B4j is not required.
B4X:
Private Sub SetSwiftbuttonColor(DesignerArgs As DesignerArgs)
    Sleep(10)
    Dim iPrimary As Int = GetColor(DesignerArgs.Arguments.Get(0))
    Dim iSecondary As Int = GetColor(DesignerArgs.Arguments.Get(1))
    For i = 2 To DesignerArgs.Arguments.Size - 1
        Dim v As B4XView = DesignerArgs.GetViewFromArgs(i)
        If v.tag Is SwiftButton Then
            Dim sbtn As SwiftButton = v.Tag
            sbtn.SetColors(iPrimary, iSecondary)
        End If
    Next
End Sub
 

Attachments

  • Project.zip
    14.2 KB · Views: 6
Upvote 1
Solution
Cookies are required to use this site. You must accept them to continue using the site. Learn more…