B4J Question [Solved]InputListAsync isn't in xui as same as MsgboxAsync,How to code?

Theera

Expert
Licensed User
Longtime User
I'm tried to learn InputListAsync() ,but I don't understand it 's not like as
MsgboxAsync(). I 've ever studied Aeric's code
B4X:
'The old code
'    Dim Res As Int
'    Res = InputList(l, "Choose a printer", -1) 'show list with paired devices
'    If Res <> DialogResponse.CANCEL Then
'        Serial1.Connect(PairedDevices.Get(l.Get(Res))) 'convert the name to mac address
'        Return True
'    End If
'-----------------------------------------------------------------------------
'The new code
    InputListAsync(l, "Choose a printer", 0, False)
    Wait For InputList_Result (res As Int)
    If res <> DialogResponse.CANCEL Then
        Serial1.Connect(PairedDevices.Get(l.Get(res))) 'convert the name to mac address
        Return True
    End If

it's different to using xui.DialogResponse_Cancel ,and In Button3_click module ,I can't declare inputlistAsync (there is message warning undeclare inputlistAsync before)
How to resolve Button3_click module's code?
B4X:
Private Sub Button3_Click
    'old code
'    Dim lstitems As List
'    lstitems.Initialize
'    lstitems.AddAll(Array As String("Item #1", "Item #2", "Item #3", "Item #4"))
'หรือ   
'    Dim lstitems As List = Array("Item #1", "Item #2", "Item #3", "Item #4")

'    Dim res As Int = fx.InputList(MainForm, lstitems, "Please choose an item", "Select Data", 0)
'    If res >= 0 Then
'        Log($"Selected item: ${lstitems.Get(res)}"$)
'    Else
'        Log("User didn't select any item.")
'    End If
'-----------------------------------------------------------------------------------------
    'new code
   
'    Dim lstitems As List
'    lstitems.Initialize
'    lstitems.AddAll(Array As String("Item #1", "Item #2", "Item #3", "Item #4"))
    'หรือ
    Dim lstitems As List = Array("Item #1", "Item #2", "Item #3", "Item #4")
    Dim res As Object=inputlistAsync(lstitems,"please choose an item","Select Data",0)
    Wait For (res) InputList_Result (myresult As Int)
    If myresult <> xui.DialogResponse_Cancel Then
        Log($"Selected item: ${lstitems.Get(myresult)}"$)
        Return True
    Else   
        Log("User didn't select any item.")
    End If
End Sub
 
Solution
It works for me.
You need to Initialize the B4XDialog.
B4X:
Private Sub Button3_Click
    Private Dialog As B4XDialog
    Dialog.Initialize(Root)
    Private lstitems As B4XListTemplate
    Dialog.Title = "Select Data"
    lstitems.Initialize
    lstitems.Options = Array("Item #1", "Item #2", "Item #3", "Item #4")
    Wait For (Dialog.ShowTemplate(lstitems, "", "", "Cancel")) Complete (Result As Int)
    If Result <> xui.DialogResponse_Positive Then
        Log("User didn't select any item.")
    Else
        Log($"Selected item: ${lstitems.SelectedItem}"$)
    End If
End Sub

Erel

B4X founder
Staff member
Licensed User
Longtime User
There is an example in the IDE help window:
B4X:
Dim options As List = Array("Red", "Green", "Blue")
InputListAsync(options, "Select Color", 0, False)
Wait For InputList_Result (Index As Int)
If Index <> DialogResponse.CANCEL Then
    Log("Selected color: " & options.Get(Index))
End If
Click on the "copy" link to copy it.

Tip: Use B4XListTemplate + B4XDialog instead.
 
Upvote 0

Theera

Expert
Licensed User
Longtime User
I have the problem that IDE B4J doesn't see InputListAsync(), How to solve?I've just updated the lastest xuiview.b4xlib.
 
Upvote 0

Theera

Expert
Licensed User
Longtime User
After I 've changed my code,I 've error message as belows

B4X:
Private Sub Button3_Click
    'old code
'    Dim lstitems As List
'    lstitems.Initialize
'    lstitems.AddAll(Array As String("Item #1", "Item #2", "Item #3", "Item #4"))
'หรือ   
'    Dim lstitems As List = Array("Item #1", "Item #2", "Item #3", "Item #4")

'    Dim res As Int = fx.InputList(MainForm, lstitems, "Please choose an item", "Select Data", 0)
'    If res >= 0 Then
'        Log($"Selected item: ${lstitems.Get(res)}"$)
'    Else
'        Log("User didn't select any item.")
'    End If
'-----------------------------------------------------------------------------------------
    'new code
   
    Private Dialog As B4XDialog
    Private lstitems As B4XListTemplate
    Dialog.Title="Select Data"
    lstitems.Initialize
    lstitems.Options = Array("Item #1", "Item #2", "Item #3", "Item #4")
    Wait For (Dialog.ShowTemplate(lstitems, "", "", "Cancel")) Complete (Result As Int)

    If Result <> xui.DialogResponse_Positive Then

        Log($"Selected item: ${lstitems.SelectedItem}"$)
    Else
        Log("User didn't select any item.")
    End If

End Sub

 
Upvote 0

aeric

Expert
Licensed User
Longtime User
B4X:
If Result <> xui.DialogResponse_Positive Then
    Log("User didn't select any item.")
Else
    Log($"Selected item: ${lstitems.SelectedItem}"$)
End If
 
Upvote 0

Theera

Expert
Licensed User
Longtime User
Even if the result of the condition is incorrect, the error still occurs.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
It works for me.
You need to Initialize the B4XDialog.
B4X:
Private Sub Button3_Click
    Private Dialog As B4XDialog
    Dialog.Initialize(Root)
    Private lstitems As B4XListTemplate
    Dialog.Title = "Select Data"
    lstitems.Initialize
    lstitems.Options = Array("Item #1", "Item #2", "Item #3", "Item #4")
    Wait For (Dialog.ShowTemplate(lstitems, "", "", "Cancel")) Complete (Result As Int)
    If Result <> xui.DialogResponse_Positive Then
        Log("User didn't select any item.")
    Else
        Log($"Selected item: ${lstitems.SelectedItem}"$)
    End If
End Sub
 

Attachments

  • DialogExample.zip
    2.9 KB · Views: 41
Upvote 0
Solution

Theera

Expert
Licensed User
Longtime User
Even though you the sourcecode, I still get error message in my code. Thank you, Aericand Erel.

Dialog.Initialize("Root") '<---has " "
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Even though you the sourcecode, I still get error message in my code. Thank you, Aericand Erel.
Root is a parent view or Object to pass to the Dialog. It is not same as initializing a view with the event name which is a String.

 
Upvote 0