B4J Question [solved] how to enable/disable toolbar buttons?

DonManfred

Expert
Licensed User
Longtime User
Based on the code i guess you should get all items with
B4X:
 joToolbar.RunMethodJO("getItems", Null)
Make sure to know which item you want to change...
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
From the code you linked to, it looks like you have a reference to the buttons that you have added. If you want to manipulate them, you'll need to set them up as global variables (which they are in the code). You can then set the Enabled state directly. :
B4X:
tbButton1.Enabled = False
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
In addition to previous replies, an example Sub to set Button Enabled property using an Array of Global Button Node(s).
Note: the toolbar example includes other than Button nodes, so a Button node needs to be determined.

The Button Array is populated depending the action required as set by the tabpanel, i.e. examples

Action1 = disable Buttons 1 and 2
B4X:
Dim Btns() As Button = Array As Button(tbButton1,tbButton2)
EnableButtons(Btns, False)

Action2 = enable Button 2
B4X:
Dim Btns() As Button = Array As Button(tbButton2)
EnableButtons(Btns, True)

Sub Enable or disable Buttons
B4X:
Sub EnableButtons(Btns() As Button, Enabled As Boolean)
   Dim ButtonList As List = joToolbar.RunMethodJO("getItems", Null)
   For Each n As Node In ButtonList
     If n Is Button Then
       Dim btn As Button = n
       For Each b As Button In Btns
         If b = btn Then btn.Enabled = Enabled       
       Next
     End If
   Next
End Sub

BTW: Thanks for pointing to the B4J HowTos.
 
Last edited:
Upvote 0

Knoppi

Active Member
Licensed User
Longtime User
Works perfect, Thank you

change a little bit

B4X:
Sub EnableButton( TagText As String, Enabled As Boolean)
    Dim ButtonList As List = joToolbar.RunMethodJO("getItems", Null)
    For Each n As Node In ButtonList
        If n Is Button Then
            Dim btn As Button = n
            If btn.Tag = TagText Then btn.Enabled = Enabled
        End If
    Next
End Sub

Thanks for pointing to the B4J HowTos.
I search first at your side, the best side for B4J HowTos.

Vielen Dank und Grüße nach Pinneberg
 
Upvote 0
Top