B4J Tutorial Msgbox / InputList

Erel

Administrator
Staff member
Licensed User
Simple message box:
B4X:
fx.Msgbox(MainForm, "This is the message", "This is the title")


Message box with result:
B4X:
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 changes...")   
End If


Note that you can pass "" as the button text to hide a button.
B4X:
fx.Msgbox2(MainForm, "Invalid value!", "Error", "I will not do it again", "", "", fx.MSGBOX_ERROR)


InputList:
B4X:
Dim items As List = Array("Item #1", "Item #2", "Item #3", "Item #4")
Dim res As Int = fx.InputList(MainForm, items, "Please choose an item", "Items", 0)
If res >= 0 Then
   Log($"Selected item: ${items.Get(res)}"$)
Else
   Log("User didn't select any item.")
End If


The message icon is the same as the owner form icon.
 

ThRuST

Well-Known Member
Licensed User
Does this also work as the inputbox in VB6? i.e. possible to input text in a textfield?
 

Osp

Member
Licensed User
Simple message box:
B4X:
fx.Msgbox(MainForm, "This is the message", "This is the title")


Message box with result:
B4X:
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 changes...")  
End If


Note that you can pass "" as the button text to hide a button.
B4X:
fx.Msgbox2(MainForm, "Invalid value!", "Error", "I will not do it again", "", "", fx.MSGBOX_ERROR)


InputList:
B4X:
Dim items As List = Array("Item #1", "Item #2", "Item #3", "Item #4")
Dim res As Int = fx.InputList(MainForm, items, "Please choose an item", "Items", 0)
If res >= 0 Then
   Log($"Selected item: ${items.Get(res)}"$)
Else
   Log("User didn't select any item.")
End If


The message icon is the same as the owner form icon.
 

Osp

Member
Licensed User
hm... the InputList example doesn't work in B4J latest version as fx.InputList is a Form not an Int. I guess it is best to have a global Inputlist and maybe redefine the list argument on the fly so one can react on an event something like selectedItemChanged or so?

B4J line: 494
Private il As Int = fx.InputList(Me, items, \
javac 1.8.0_74
src\sabatschus\cajacentral\main.java:1155: error: incompatible types: Class<CAP#1> cannot be converted to Form
_il = _fx.InputList((anywheresoftware.b4j.objects.Form)(main.getObject()),_items,"Elegir un resultado","Resultados busceda",(int) (0));
 
Last edited:

Osp

Member
Licensed User
hm... the InputList example doesn't work in B4J latest version as fx.InputList is a Form not an Int. I guess it is best to have a global Inputlist and maybe redefine the list argument on the fly so one can react on an event something like selectedItemChanged or so?

B4J line: 494
Private il As Int = fx.InputList(Me, items, \
javac 1.8.0_74
src\sabatschus\cajacentral\main.java:1155: error: incompatible types: Class<CAP#1> cannot be converted to Form
_il = _fx.InputList((anywheresoftware.b4j.objects.Form)(main.getObject()),_items,"Elegir un resultado","Resultados busceda",(int) (0));
My bad.. reading the error a bit more precisely... it was just using Me as the owner did not work!
Solved... Null for example as Owner works!
 
Top