B4J Question (Solved) Options Dialog of PreferencesDialog

aeric

Expert
Licensed User
Longtime User
How can I access the items such as Cancel button or Search input hint for the Options dialog?
Let say I want to localize/change the text to other language or change their properties?
And the properties do not persist when I clicked on Cancel.

1633539402614.png


Sample project attached.

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    CreateDialog1
End Sub

Private Sub B4XPage_Resize(Width As Int, Height As Int)
    If PrefDialog1.IsInitialized And PrefDialog1.Dialog.Visible Then PrefDialog1.Dialog.Resize(Width, Height)
End Sub

Private Sub BtnShow_Click
    ShowDialog1
End Sub

Private Sub CreateDialog1
    PrefDialog1.Initialize(Root, "Product", 300dip, 250dip)
    PrefDialog1.Dialog.OverlayColor = xui.Color_ARGB(128, 0, 10, 40)
    PrefDialog1.Dialog.TitleBarHeight = 50dip
    PrefDialog1.LoadFromJson(File.ReadString(File.DirAssets, "template.json"))
End Sub

Private Sub ShowDialog1
    PrefDialog1.Dialog.TitleBarColor = xui.Color_RGB(65, 105, 225)
    PrefDialog1.Title = "Product"
    Dim Item As Map = CreateMap("Product Code": "", "Category": "", "Product Name": "", "id": 0)
    Dim sf As Object = PrefDialog1.ShowDialog(Item, "CONFIRM", "CANCEL ACTION")
    Dim btnCancel As B4XView = PrefDialog1.Dialog.GetButton(xui.DialogResponse_Cancel)
    btnCancel.Width = btnCancel.Width + 60dip
    btnCancel.Left = btnCancel.Left - 60dip
    btnCancel.TextColor = xui.Color_Red
    Dim btnOk As B4XView = PrefDialog1.Dialog.GetButton(xui.DialogResponse_Positive)
    btnOk.Width = btnOk.Width + 20dip
    btnOk.Left = btnCancel.Left - btnOk.Width
    'Sleep(0)
    'PrefDialog1.CustomListView1.sv.Height = PrefDialog1.CustomListView1.sv.ScrollViewInnerPanel.Height + 10dip
    Wait For (sf) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Log("OK")
    End If
End Sub
 

Attachments

  • PreferencesDialog.zip
    3.5 KB · Views: 335
Solution
Tip: use the comment link, at the top of B4XMainPage, to create the zip file (https://www.b4x.com/android/forum/t...elated-to-shared-files-folder.124408/#content).

Update to v1.74:

B4X:
Private Sub CreateDialog1
    PrefDialog1.Initialize(Root, "Product", 300dip, 250dip)
    PrefDialog1.Dialog.OverlayColor = xui.Color_ARGB(128, 0, 10, 40)
    PrefDialog1.Dialog.TitleBarHeight = 50dip
    PrefDialog1.LoadFromJson(File.ReadString(File.DirAssets, "template.json"))
    PrefDialog1.SetEventsListener(Me, "PrefDialog1") '<-- must add to handle events.
End Sub

Private Sub ShowDialog1
    PrefDialog1.Dialog.TitleBarColor = xui.Color_RGB(65, 105, 225)
    PrefDialog1.Title = "Product"
    Dim Item As Map =...

Erel

B4X founder
Staff member
Licensed User
Longtime User
Tip: use the comment link, at the top of B4XMainPage, to create the zip file (https://www.b4x.com/android/forum/t...elated-to-shared-files-folder.124408/#content).

Update to v1.74:

B4X:
Private Sub CreateDialog1
    PrefDialog1.Initialize(Root, "Product", 300dip, 250dip)
    PrefDialog1.Dialog.OverlayColor = xui.Color_ARGB(128, 0, 10, 40)
    PrefDialog1.Dialog.TitleBarHeight = 50dip
    PrefDialog1.LoadFromJson(File.ReadString(File.DirAssets, "template.json"))
    PrefDialog1.SetEventsListener(Me, "PrefDialog1") '<-- must add to handle events.
End Sub

Private Sub ShowDialog1
    PrefDialog1.Dialog.TitleBarColor = xui.Color_RGB(65, 105, 225)
    PrefDialog1.Title = "Product"
    Dim Item As Map = CreateMap("Product Code": "", "Category": "", "Product Name": "", "id": 0)
    Wait For (PrefDialog1.ShowDialog(Item, "CONFIRM", "CANCEL ACTION")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Log("OK")
    End If
End Sub

Private Sub PrefDialog1_BeforeDialogDisplayed (Template As Object)
    Dim btnCancel As B4XView = PrefDialog1.Dialog.GetButton(xui.DialogResponse_Cancel)
    btnCancel.Width = btnCancel.Width + 60dip
    btnCancel.Left = btnCancel.Left - 60dip
    btnCancel.TextColor = xui.Color_Red
    Dim btnOk As B4XView = PrefDialog1.Dialog.GetButton(xui.DialogResponse_Positive)
    If btnOk.IsInitialized Then
        btnOk.Width = btnOk.Width + 20dip
        btnOk.Left = btnCancel.Left - btnOk.Width
    End If
End Sub
 
Upvote 0
Solution
Top