Android Question B4XPreferenceDialog I cant add the result in a List.

Status
Not open for further replies.

Brian Michael

Member
Licensed User
Hi im tryin to make a Form Request and add in a list.

I have this code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    Private xui As XUI
    Private OptionsFile As String = "options2.map"
End Sub

Sub Globals
    Private prefdialog As PreferencesDialog
    Private TextArea1 As B4XView
    Private Options1 As Map
    Public newClientsRequest As List
    Private ListView1 As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    prefdialog.Initialize(Activity, "SOLICITUD : NUEVO CLIENTE", 300dip, 400dip)
    Options1.Initialize
    xui.SetDataFolder ("preferences")
    prefdialog.LoadFromJson(File.ReadString(File.DirAssets, "form_newclient.json"))
    prefdialog.SetOptions("city", File.ReadList(File.DirAssets, "cities.txt"))
    prefdialog.SetOptions("state", File.ReadList(File.DirAssets, "states.txt"))
    newClientsRequest.Initialize
    LoadSavedData

End Sub

Sub SaveData
    Dim ser As B4XSerializator
    File.WriteBytes(xui.DefaultFolder, OptionsFile, ser.ConvertObjectToBytes(newClientsRequest))
End Sub

Sub LoadSavedData
    Try
        
        If File.Exists(xui.DefaultFolder, OptionsFile) Then
            Dim ser As B4XSerializator
            Dim opt() As Object = ser.ConvertBytesToObject(File.ReadBytes(xui.DefaultFolder, OptionsFile))
            For Each client As Map In opt
                newClientsRequest.Add(client)
            Next
            LoadAllClientList
        End If
    Catch
        Log(LastException)
    End Try
End Sub

Sub btnOptions1_Click
    Wait For (prefdialog.ShowDialog(Options1, "OK", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        newClientsRequest.Add(Options1)
        ListView1.AddSingleLine2(Options1.Get("name"),Options1)
        PrintClient(Options1)
        Options1.Clear
    End If
    'LoadAllClientList
End Sub


Sub PrintClient (Options As Map)
    Dim sb As StringBuilder
    sb.Initialize
    For Each key As String In Options.Keys
        If key = "" Then Continue 'separators
        sb.Append(key).Append(": ").Append(Options.Get(key)).Append(CRLF)
    Next
    TextArea1.Text = sb.ToString
End Sub

Sub LoadAllClientList
    ListView1.Clear
    For Each client As Map In newClientsRequest
        ListView1.AddSingleLine(client.Get("name"))
        Log(client)
    Next
    
End Sub
Private Sub ListView1_ItemClick (Position As Int, Value As Object)
    PrintClient(newClientsRequest.Get(Position))
    Log(newClientsRequest)
    Log(newClientsRequest.Get(Position))
End Sub

And when i try to get the item, the list its empty:

1626192200174.png


1626192216830.png



But the list doesnt add the item.
Help!
 
Status
Not open for further replies.
Top