ขอขอบคุณ Erel,Fernando Sola,Klaus, และ Aeric ณ ที่นี่ ด้วยครับ อ้างอิงถึง
www.b4x.com
หมายเหตุ
กรณี B4A ที่เขียนใน Module Button3_Click สามารถเขียนโดยใช้ InputListAsync() ได้ ส่วน B4J และ B4i ให้เลือกใช้
B4XListTemplate จากไลบารี่ XUI Views. แทน
Msgbox / InputList
Simple message box: fx.Msgbox(MainForm, "This is the message", "This is the title") Message box with result: Dim res As Int = fx.Msgbox2(MainForm, "Do you want to save changes?", "Save", _ "Yes", "Cancel", "No", fx.MSGBOX_WARNING) If res = fx.DialogResponse.POSITIVE Then Log("Saving...
B4X:
Private Sub Button1_Click
'old code
'fx.Msgbox(MainForm, "This is the message", "This is the title")
'-----------------------------------------------------------------------------------
'new code
xui.MsgboxAsync("This is the message", "This is the title")
End Sub
B4X:
Private Sub Button2_Click
'old code
' Dim res As Int = fx.Msgbox2(MainForm, "Do you want to save changes?", "Save Data", "Yes", "Cancel", "No", fx.MSGBOX_WARNING)
' If res = fx.DialogResponse.POSITIVE Then
' Log("Saving changes...")
' End If
'-------------------------------------------------------------------------------------
'new code
' Dim res As Object= xui.Msgbox2Async("Do you want to save changes?","Save Data","Yes","Cancel","No", fx.LoadImage(File.DirAssets,"Iconwarning.png"))
'หรือ
Dim res As Object= xui.Msgbox2Async("Do you want to save changes?","Save Data","Yes","Cancel","No", xui.LoadBitmap(File.DirAssets,"Iconwarning.png"))
Wait For (res) Msgbox_Result (Result As Int)
If Result = xui.DialogResponse_Positive Then
Log("Saving changes...")
End If
End Sub
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
'Dialog.Initialize("Root") <----ถ้ามีเครื่องหมายคำพูดจะเกิดข้อผิดพลาด
Dialog.Initialize(Root)
Dialog.Title="Select Data"
Private lstitems As B4XListTemplate
lstitems.Initialize
lstitems.Options = Array("Item #1", "Item #2", "Item #3", "Item #4")
Wait For (Dialog.ShowTemplate(lstitems, "", "", "ยกเลิก")) 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
หมายเหตุ
กรณี B4A ที่เขียนใน Module Button3_Click สามารถเขียนโดยใช้ InputListAsync() ได้ ส่วน B4J และ B4i ให้เลือกใช้
B4XListTemplate จากไลบารี่ XUI Views. แทน
B4X:
'Example from the Aeric's code in B4A
'Changing InputListTobeInputListAsync
'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
Last edited: