Android Question [Solution] PreferencesDialog does not return NULL

T201016

Active Member
Licensed User
Longtime User
Hello,
I have a question for PreferencesDialog users.

Well, I cannot cope with editing the COMPANY field (see photo).
When I am about to delete all its contents to NULL form and after accepting
all other fields, however, the contents of Item.Get ("Company") remain
no change, and expected NULL as intended.

code snippet:
Wait For (PrefDialog.ShowDialog(Item, "OK", "CANCEL")) Complete (Result As Int):
If RowId > 0 Then 'View the content of the fields
        Dim Item As Map = B4XTable1.GetRow(RowId)
        Dim components() As String = Regex.Split(" ",Item.Get("Name"))
        Item.Put("FirstName", components(0))
        Item.Put("LastName",  components(1))
    End If
   
    Wait For (PrefDialog.ShowDialog(Item, "OK", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Dim id As Int
        Dim params As List
        params.Initialize
       
        If RowId = 0 Or Action >=2 And Action <=3 Then 'add new row
            If B4XSwitch1.Value Then B4XSwitch1_ValueChanged(False)
            id = B4XTable1.mCurrentCount + 1 'new rowid
        Else
            id = Item.Get("CustomerId")
        End If
       
'        If Item.Get("Company") = "null" Then Item.Put("Company",Null)
'       If Item.Get("Address") = "null" Then Item.Put("Address",Null)

        params.AddAll(Array(id, Item.Get("FirstName"), Item.Get("LastName"), Item.Get("Company"), Item.Get("Address"), Item.Get("Email"))) 'keys based on the template json file

thanks for the help in advance.
 

Attachments

  • ScreenShot00014.png
    ScreenShot00014.png
    378 KB · Views: 153

T201016

Active Member
Licensed User
Longtime User
Dim ft As B4XFloatTextField = PrefDialog.CustomListView1.GetPanel(i).GetView(0).Tag '-------->>> Solution !!!
If ft.Text.Length = 0 Then ------------------------------------------------------------------>>> Solution !!!

Hello all,
I just fixed the problem How to get NULL for an edited field.
Previously, in editing a field after all its contents had been cleared
I always got the previous contents of the field, and I should get NULL. This has always been the case when deleting content
fields, while changing the previous content to a different dialog it returned the correct content of the edited field.

Admittedly, this is a bit of a cumbersome method as giving as input (see: Item As Map) are values
I should look for feedback in the 'Item' output.
What do you think about it?

B4X:
Private Sub ShowDialog(Item As Map, RowId As Long, Action As Int)
    
    If RowId > 0 Then 'View the content of the fields
        Dim Item As Map = B4XTable1.GetRow(RowId)
        Dim components() As String = Regex.Split(" ",Item.Get("Name"))
        Item.Put("FirstName", components(0))
        Item.Put("LastName",  components(1))
    End If
    
    Dim sf As Object = PrefDialog.ShowDialog(Item, "OK", "CANCEL")
    For i = 0 To PrefDialog.PrefItems.Size - 1
        Dim pi As B4XPrefItem = PrefDialog.PrefItems.Get(i)
        If pi.ItemType = PrefDialog.TYPE_TEXT Then
            Dim ft As B4XFloatTextField = PrefDialog.CustomListView1.GetPanel(i).GetView(0).Tag
            ft.TextField.Font = xui.CreateDefaultBoldFont(14)
        End If
    Next
    
    Wait For (sf) Complete (Result As Int)
    '
    For i = 0 To PrefDialog.PrefItems.Size - 1
        Dim pi As B4XPrefItem = PrefDialog.PrefItems.Get(i)
        If pi.ItemType = PrefDialog.TYPE_TEXT Then
            Dim ft As B4XFloatTextField = PrefDialog.CustomListView1.GetPanel(i).GetView(0).Tag    '-------->>> Solution !!!
            If ft.Text.Length = 0 Then '------------------------------------------------------------------>>> Solution !!!
                Select i
                    Case 1
                    Item.Put("FirstName",ft.Text)
                  Case 2
                    Item.Put("LastName",ft.Text)
                  Case 3
                    Item.Put("Company",ft.Text)
                  Case 4
                    Item.Put("Address",ft.Text)
                  Case 5
                    Item.Put("Email",ft.Text)
                End Select
            End If
        End If
    Next
    '
    If Result = xui.DialogResponse_Positive Then
    ...
 
Upvote 0
Top