B4J Question BCText - multiple buttons with tags

johnmie

Active Member
Licensed User
Longtime User
When I first read about Erel's BCtext in this Forum (not the one in Rome) I was immediately fascinated and decided to use this in my 1st B4J project as a learning exercise (both for B4X-Pages and B4J). It said in that post (May 2019) "not 100% ready and especially it is missing another layer above the engine that will make it easier to build the text with the various options", but I could not find that layer, so I started to roll my own. Out came a tool to build an expandable xCLV list including a button designer and a table designer that lets you import tab-delimited lists with links to a DB.

All works now very nicely except for this thing with the buttons as there could be several expanded panels with one or more buttons with different functions (and I don't want to create a separate sub for each individual button as this would make it very complicated for the future users of this layer tool).

Sub createButton:
sub createButton
        Dim btn As Button
        btn.Initialize("btn")
        Dim xbtn As B4XView = btn
        xbtn.Text = TextField1.Text '&" "&Q.nrow
        xbtn.textColor = xui.Color_White
        Select Case Style1.SelectedValue
            Case "dark"
                xbtn.Color = xui.Color_DarkGray
            Case "blue"
                xbtn.Color = xui.Color_Blue
            Case "red"
                xbtn.Color = xui.Color_Red
            Case Else '"light"
                xbtn.Color = xui.Color_LightGray
                xbtn.textColor = xui.Color_Black
        End Select
        xbtn.Tag = Label4.text
        xbtn.SetLayoutAnimated(0, 0, 0, TextField3.Text, TextField4.text) 'these are actually  numbers
        
        B4XPages.MainPage.BBCodeViewM.Views.Put($"btn${Q.nRow}"$,xbtn)   '
'        Dim Out As String =$"[a=2]lets add a button [View=btn${Q.nRow}/] and see whats happens[/a]"$ '${Q.nRow}
        Dim Out As String =$" [View=btn${Q.nRow}/] "$ 'btn${Q.nRow
        Q.nRow=Q.nRow+1
'        E1.TextArea1.Text = E1.TextArea1.Text & CRLF&Out
        Dim A As String = E1.TextArea1.Text
        Dim F As Int = E1.findstart
        If F < 1 Or F > E1.TextArea1.Text.Length - 2 Then
            E1.TextArea1.Text = E1.TextArea1.Text & CRLF&Out
        Else
            E1.TextArea1.Text = A.SubString2(0,E1.findstart).trim &Out &  A.SubString(E1.findstart).trim
        End If
'        Log("E new text from "&E1.findstart&CRLF&E1.TextArea1.Text)
        E1.showBB
End Sub

I tried several variations on line 21 with different Sub btn_click variants and even to wrap the button in an URL but could not see any result upon clicking on any of the buttons, because I could not figure out a way to add/recover multiple buttons with tags to jump to different subs (as a button on panel one could have the same function as button on panel 5, e.g. "print list").
Perhaps the BBListitem part in the library could be tweaked, I'll have a look.

Any Idea to help solving this enigma would be more than helpful. Thank you in advance.
john m.
 

johnmie

Active Member
Licensed User
Longtime User
Thank you,Erel, this is exactly what I was trying to figure out.
my xbutton has a tag on line 18 but in
btn_click:
Sub btn_click
    Dim t As B4XView
    t = Sender
    Dim x As Int = t.Tag
    Log("button clicked: "&x&",  name="&t.Parent&",  tag="&x)
End Sub
nothing happens.
I also tried Dim t As Button - absolute silence.

What have I done wrong?
rgs

PS please ignore this message and that the problem even existed.
I just discovered a stupid error of mine (or lack of logical thinking) as the buttons have to reconstructed and their numbers and corresponding tags could change with every visit of the same page.
 
Upvote 0

johnmie

Active Member
Licensed User
Longtime User
Almost solved: I changed strategy since the same button can appear more than once on the same BBCodeview and on several expandable CLV views,
I create buttons only once as *.png images, save to AppData and wrap the images into commands. This offers flexibility ...0, "PNG") Ostream.Close End Sub [/CODE]
 

Attachments

  • 3buttons.png
    3buttons.png
    2.1 KB · Views: 84
Upvote 0
Top