Android Question [RESOLVED] B4XDialog - Setting ToggleButton States - No working correctly

Discussion in 'Android Questions' started by Jmu5667, Aug 15, 2019 at 11:07 AM.

  1. Jmu5667

    Jmu5667 Well-Known Member Licensed User

    Hello

    I have the following code:

    Code:
    Sub runtime_settings_access
      
       
    Dim p As B4XView = xui.CreatePanel("")
      
       p.SetLayoutAnimated(
    00090%x,270dip)
       p.LoadLayout(
    "runtime_settings")

       
    ' // create the dialog
       dialog.Initialize(Activity)
       dialog.BackgroundColor = 
    Colors.White
       dialog.TitleBarColor = 
    0xFFC8001F
       dialog.TitleBarTextColor = 
    Colors.white
       dialog.Title = 
    "Options"
       dialog.ButtonsColor = 
    Colors.Gray
       dialog.ButtonsTextColor = 
    Colors.black
       dialog.PutAtTop = 
    True 'put the dialog at the top of the screen
       dialog.ShowCustom(p, "OK""""")
      
       draw_user_options
       set_user_access_permissions
       
    ' // wait for response
       Wait For (dialog.ShowCustom(p, "OK""""")) Complete (Result As Int)
      
      
    End Sub

    Public Sub draw_user_options
      
      
       
    ' // lone working
       If APPSET.RT_am.worktype = 1 Then
           tbWorkType.Checked = 
    True
       
    Else
           tbWorkType.Checked = 
    False
       
    End If
       
    ' // mandown
       If APPSET.licence.FEATURE(APP_FEATURE.mandown) Then
           
    If APPSET.mandown.enabled = 1 Then
               tbManDown.Checked = 
    True
           
    Else
               tbManDown.Checked = 
    False
           
    End If
       
    Else
           lblManDown.Color = 
    Colors.red
           tbManDown.Enabled = 
    False
       
    End If
              
       
    ' // audio warnings
       If APPSET.RT_am.audio_warnings = 1 Then
           tbAudibleWarnings.Checked = 
    True
       
    Else
           tbAudibleWarnings.Checked = 
    False
       
    End If
       
    ' // vibration warnings
       If APPSET.RT_am.vibration_warnings = 1 Then
           tbVibrationWarnings.Checked = 
    True
       
    Else
           tbVibrationWarnings.Checked = 
    False
       
    End If

    End Sub

    Sub set_user_access_permissions
      
       
    Log("set_user_access_permissions")
       
    ' // LW State permission
       If APPSET.userLWswitch = 1 Then
           
    Log("tbWorkType.Enabled = True")
           tbWorkType.Enabled = 
    True
           tbWorkType.visible = 
    True
       
    Else
           
    Log("tbWorkType.Enabled = False")
           tbWorkType.Enabled = 
    False
           tbWorkType.visible = 
    False
       
    End If
       
    ' // MD State permission
       If APPSET.userMDswitch = 1 Then
           
    Log("tbManDown.Enabled = True")
           tbManDown.Enabled  = 
    True
       
    Else
           
    Log("tbManDown.Enabled = False")
           tbManDown.Enabled  = 
    False
       
    End If
       
    ' // AUDIO/VIBRATION Permission
       If APPSET.uwc_notify = 1 Then
           
    Log("APPSET.uwc_notify = 1")
           tbAudibleWarnings.Enabled = 
    False
           tbVibrationWarnings.Enabled = 
    False
       
    Else
           
    Log("APPSET.uwc_notify = 0")
           tbAudibleWarnings.Enabled = 
    True
           tbVibrationWarnings.Enabled = 
    True
       
    End If

    End Sub
    when executed, setting the enabled state of the toggle button to false does not work, but I can set the visibility to false as it does work, is this a bug ?

    Using b4a 9.3


    Regards

    John.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Why not use the much nicer B4XSwitch?

    Can you upload a small project with this code and the layout?
     
  3. Jmu5667

    Jmu5667 Well-Known Member Licensed User

    ok, upload shortly
     
  4. Jmu5667

    Jmu5667 Well-Known Member Licensed User

    Hello

    Attached is the sample you requested with the actual bal file used in the original app. I have included the visibility test also to demonstrate the issue.

    Regards

    John.
     

    Attached Files:

  5. Jmu5667

    Jmu5667 Well-Known Member Licensed User

    Updated with BX4Xswitch to show difference
     

    Attached Files:

  6. Erel

    Erel Administrator Staff Member Licensed User

    You need to do it like this:
    Code:
    Dim sf As Object = dialog.ShowCustom(p, "OK""""")
    set_user_access_permissions
    Wait For (sf) Complete (Result As Int)
    Somewhere in B4XDialog code it enables the underlying controls when you call Show.
     
    Jmu5667 likes this.
  7. Jmu5667

    Jmu5667 Well-Known Member Licensed User

    Thanks for the help Erel, I think I will use the switch's going forward :)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice