Android Question B4A Prefdialogs forms : disable item field

mike1967

Active Member
Licensed User
Longtime User
helllo whit this:
B4X:
prefdialog.Initialize(B4XPages.GetNativeParent(Me),Main.attrezzatura,800,900)
        prefdialog.LoadFromJson(File.ReadString(File.DirAssets, "impianti.json"))
How i can disable programmatically an item in the form with key "datacoll" ?
Can help me ?
Thanks in advance
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The code depends on the specific item layout.

Example:
B4X:
Sub Button2_Click
    p.Title = "dc342"
    p.Theme = p.THEME_DARK
    Dim sf As Object = p.ShowDialog(Data(1), "OK", "CANCEL")
    SetTwoLabelsItemState(p, "Birthday", False)
    Wait For (sf) Complete (Result As Int)
End Sub

Private Sub SetTwoLabelsItemState (Pref As PreferencesDialog, Key As String, Enabled As Boolean)
    For i = 0 To Pref.CustomListView1.Size - 1
        Dim pi As B4XPrefItem = Pref.CustomListView1.GetValue(i)
        If pi.Key = Key Then
            Pref.CustomListView1.GetPanel(i).GetView(0).Enabled = Enabled
            Pref.CustomListView1.GetPanel(i).GetView(1).Enabled = Enabled
        End If
    Next
End Sub

Note that the items will not be enabled automatically. Either set the state each time, or call p.CustomListView1.Clear before you show the dialog. It will cause the items to be recreated.
 
Upvote 0

mike1967

Active Member
Licensed User
Longtime User
The code depends on the specific item layout.

Example:
B4X:
Sub Button2_Click
    p.Title = "dc342"
    p.Theme = p.THEME_DARK
    Dim sf As Object = p.ShowDialog(Data(1), "OK", "CANCEL")
    SetTwoLabelsItemState(p, "Birthday", False)
    Wait For (sf) Complete (Result As Int)
End Sub

Private Sub SetTwoLabelsItemState (Pref As PreferencesDialog, Key As String, Enabled As Boolean)
    For i = 0 To Pref.CustomListView1.Size - 1
        Dim pi As B4XPrefItem = Pref.CustomListView1.GetValue(i)
        If pi.Key = Key Then
            Pref.CustomListView1.GetPanel(i).GetView(0).Enabled = Enabled
            Pref.CustomListView1.GetPanel(i).GetView(1).Enabled = Enabled
        End If
    Next
End Sub

Note that the items will not be enabled automatically. Either set the state each time, or call p.CustomListView1.Clear before you show the dialog. It will cause the items to be recreated.
I try the code and work only one time. If when the field is disable and click on another item field date type it is reenabled.
 
Upvote 0
Top