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
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.
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

b4xdialog$ResumableSub_ShowTemplate.resume (java line: 1141)
java.lang.RuntimeException: java.lang.NullPointerException: Cannot read field "eventsTarget" because "mine" Is Null
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:523)
at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:469)
at b4j.example.b4xdialog$ResumableSub_ShowTemplate.resume(b4xdialog.java:1141)
at b4j.example.b4xdialog._showtemplate(b4xdialog.java:1109)
at b4j.example.main$ResumableSub_Button3_Click.resume(main.java:170)
at b4j.example.main._button3_click(main.java:137)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.BA$1.run(BA.java:236)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: java.lang.NullPointerException: Cannot read field "eventsTarget" because "mine" Is Null
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:498)
... 16 more
 
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: 31
Upvote 0
Solution

Theera

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
Even though you the sourcecode, I still get error message in my code. Thank you, Aericand Erel.

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