Android Question I want the second options to appear as the second options according to the choice from the first options B4XPreferenciesDialog

alfaiz678

Active Member
Licensed User
I want the second options to appear as the second options according to the choice from the first options B4XPreferenciesDialog
I tried an event BeforeDialogDisplayed
and it does not work, the data is only downloaded on the first run and does not change

B4X:
Private Sub PrefDialog_BeforeDialogDisplayed (Template As Object)
    PrefDialog.SetOptions("Name", NameList)

End Sub
 

alfaiz678

Active Member
Licensed User
I want the second options to appear as the second options according to the choice from the first options B4XPreferenciesDialog
I tried an event BeforeDialogDisplayed
and it does not work, the data is only downloaded on the first run and does not change

B4X:
Private Sub PrefDialog_BeforeDialogDisplayed (Template As Object)
    PrefDialog.SetOptions("Name", NameList)

End Sub
When I only try ideas about this, I tried to reload the list in each one at the event
B4X:
Private Sub PrefDialog_BeforeDialogDisplayed (Template As Object)
PrefDialog.SearchTemplate.SetItems(NameList)
It worked a bit but you get random in adding data to data
In these get the same data in all the option boxes

In conclusion, I tried many things in this event and did not succeed, I deleted many of them during the experiment
 
Last edited:
Upvote 0

alfaiz678

Active Member
Licensed User
I think I found some tricks that work. I will post them later after they are completed.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Hi:

I use something like this for showing differents Preferences Dialogs depending on the options you select. Maybe you can get some inspiration

B4X:
Private Sub AddChecklist
    Dim mChecklist as Map
    mChecklist.Initialize
    'B4XPages.MainPage.ObtenerLocalizacion
    Dim lastCalled As String = "tipo" 'We save the last pf (preference dialog) showed. The last pf showed must contain some value to stop the Do Until. In this case, a field called "site"
    Dim json_torre As Map
    Dim file_json As String
    Wait For(ShowForm(lastCalled)) Complete (Result As Int)
    Do Until ("#@" <> mChecklist.GetDefault("site", "#@") Or Result <> xui.DialogResponse_Positive) 'I use #@ as a strange string
        lastCalled = mDialogs.Get(lastCalled)
        Log(lastCalled & ".json")
        file_json = lastCalled & ".json"
        If File.Exists(File.DirAssets, file_json.ToLowerCase) Then
            Log("json file doesn't exist")
            Log(json_torre)
            Wait For(ShowForm(lastCalled)) Complete (Result As Int)
        Else
            B4XPages.MainPage.toast.Initialize(Root)
            B4XPages.MainPage.toast.pnl.Color = xui.Color_Green
            B4XPages.MainPage.toast.DefaultTextColor = xui.Color_White
            B4XPages.MainPage.toast.Show("This option doesn't exist yet")
            Log("Error, json not found")
            Result = xui.DialogResponse_Negative
        End If
      
    Loop
    If Result = xui.DialogResponse_Positive Then
        Log("mChecklist: & " & mChecklist)
        Dim f As String = mChecklist.Get("Torre Modelizada") & ".json"
  
        If File.Exists(File.DirAssets, f.ToLowerCase) Then
            Dim s1 As String = File.ReadString(File.DirAssets, f.ToLowerCase)
            Log("s1: " & s1)
            Dim m As Map = s1.As(JSON).ToMap 'ignore
            For Each Key As String In mChecklist.Keys
                m.Put(Key, mChecklist.Get(Key))
            Next
            json_torre = m
        Else
            Log("Theres no model for this tower")
'            toast.Show("Theres no model for this tower")
            json_torre = mChecklist
        End If
  
        B4XPages.MainPage.SQL1.ExecNonQuery2($"INSERT INTO `cve` (`site`, `json_data`) VALUES (?,?)"$, Array As Object(mChecklist.Get("site"), json_torre.As(JSON).ToString))
        'clvChecklist.AddTextItem(mChecklist.Get("site") & " " & mChecklist.Get("tipo") & " " & mChecklist.Get("CVE"), json_torre)
        clvChecklist.Add(CreateListItem(json_torre, clvChecklist.AsView.Width, 80dip), json_torre)
    End If
  
End Sub

Public Sub ShowForm (pf As String) As ResumableSub
    Log("Load: " & pf & ".json")
    pfChecklist = B4XPages.MainPage.ViewsCache1.CreatePreferencesDialog(Root, pf & ".json")
    Wait For (pfChecklist.ShowDialog(mChecklist, "OK", "Cancel")) Complete (Result As Int)
    Return Result
End Sub
 
Upvote 0

alfaiz678

Active Member
Licensed User
I think I found some tricks that work. I will post them later after they are completed.
Simple solution but for me it did the job.
I just changed the variable NestedDialogItemIndex
from Private
to Public
 

Attachments

  • PreferencesDialogTest.zip
    9.7 KB · Views: 12
Upvote 0
Solution
Top