Android Question Inputlist in b4x

netsistemas

Active Member
Licensed User
Longtime User
how to show a modal selector in b4x (java and android) .
A simple list with 2 or more opcion

i doing the below code, but the first error for me is how set Mainform in b4x


B4X:
            Dim r As List
            dim Linea1 as string, linea2 as string
                Dim m As Int
                r.Initialize
    Linea1= "opcion1"
    Linea2= "opcion 2"
      
                r.AddAll(Array As String(Linea1, Linea2))
              
                #if b4j
                  
                    Dim fx As JFX 'is necessare referenci jfx library'
                    m = fx.InputList(Main_O_WHATtoPut, r, "Seleccione ", "Productos", 0) 'me vs MainForm
                    If m >= 0 Then
                        'Log($"Selected item: ${items.Get(m)}"$)
                    Else
                        'Log("User didn't select any item.")
                    End If
                #else 'b4a'
                  
                    Dim x As id 'need reference id libreary'
                  
                    m = x.InputList1(r, "Opciones")
                #end if
          
                Select Case m
                    Case 0    '
                        'correcta la primera
                    Case 1 '
            'lo segundo'
                      
                    Case Else
                      
                End Select
      
            End If
            ..


i change to public a variable in main:
B4X:
Sub Process_Globals
    Private fx As JFX
    Public MainForm As Form

End Sub

and put
B4X:
m = fx.InputList(Main.MainForm   , r, "Seleccione el producto", "Productos", 0) 'me vs MainForm

instead
Main_O_WHATtoPut
but i think this is not the best solution
 
Last edited:

netsistemas

Active Member
Licensed User
Longtime User
Ok. Solved.
This is my finaly code:

B4X:
Sub GetOpcion2k(Lineas As List ) As ResumableSub
    'wrap it with a timed template

    Dim Lista As List
    Lista.Initialize
    Dim Elemento As TD_ListaDuplicados
    Dim Cuenta As Long

    For Cuenta = 0 To Lineas.Size - 1
        Elemento  = Lineas.Get(Cuenta)
        Lista.Add ((Cuenta + 1) & " º " & Elemento.Producto  )
    Next
   
   
    options.Initialize
    options.Options = Lista ' Array(Linea1,Linea2)' Array("Cat", "Dog", "Fish", "Crocodile")
    options.AllowMultiSelection = False
    options.MultiSelectionMinimum = 1
   
   
    Dim TimedTemplate As B4XTimedTemplate
    TimedTemplate.Initialize(options)
    TimedTemplate.TimeoutMilliseconds = 30000 'close after 10 seconds (this is the default value)
    Wait For (Dialog.ShowTemplate(TimedTemplate, "OK", "", "CANCEL")) Complete (Result As Int)
    'If Result = xui.DialogResponse_Positive Then
    If  options.SelectedItem <> "" Then
        'Dialog.Show($"You selected: ${options.SelectedItems}"$, "OK", "", "")
        Dim IDLinea As Long
        IDLinea = options.SelectedItem.SubString2(0,1)
        Return Lineas.Get(IDLinea-1)
    Else
        Elemento.Initialize
        Return Elemento
    End If
End Sub

.....
           
            If Lineas.Size > 1 Then
                   
                Wait For (GetOpcion2k(Lineas)) Complete (Result As TD_ListaDuplicados)
            Else
                Result = Lineas.Get(0)
            End If
...

'in create activiy:
    Dialog.Initialize (Root)
    Dialog.Title = "Varios productos"

'and in class_globals:
Sub Class_Globals
   
    Private Dialog As B4XDialog
    Private options As B4XListTemplate
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Do you have an example of that? I want to remove the inputList
In the first post of the below link by Erel there is an example for B4XInputList and B4XDialog. If you get stuck, post your code or project and come back. We will help you.
Note, the community prefers that you have created a new thread since the thread is a couple of years old.
 
Upvote 1
Top