I have a problem getting the selected index in a B4XComboBox inside a B4X dialog. If you select anything else than selectedindex 0 nothing is selected and loops again as it is supposed to do. The same code works perfect in B4A. Debugging it I noticed that if you select an index greater than 0 the selectedindex turns to -1 (Checked in the line immediately after the asterisks). I use XUI Views v2.13.
Here is the code:
B4X:
Sub GetNumber As ResumableSub
Dim dialog As B4XDialog
Dim xui As XUI
Dim p As B4XView = xui.CreatePanel("")
Dim lv As LayoutValues = GetDeviceLayoutValues
p.SetLayoutAnimated(0, 0, 0, lv.Width*0.8, lv.Height*0.6)
p.LoadLayout("GetNum")
locmain.LocalizeLayout(p)
dialog.Initialize(Page1.RootPanel)
Dim l As List
l.Initialize
l.Add("- Please select -")
For ii = 1 To 10
l.Add(ii)
Next
cmbGetNum.SetItems(l)
Dim iNum As Int
Dim bProceed As Boolean = False
Do While bProceed = False
dialog.PutAtTop = True 'put the dialog at the top of the screen
Wait For (dialog.ShowCustom(p, locmain.Localize("Ok"), "", locmain.Localize("Cancel"))) Complete (Result As Int)
'*******************************************
Dim iSel As Int = cmbGetNum.SelectedIndex
If Result = xui.DialogResponse_Positive Then
Select Case iSel
Case -1
'
Case 0
'
Case Else
iNum = cmbGetNum.GetItem(iSel)
bProceed = True
End Select
Else If Result = xui.DialogResponse_Cancel Then
iNum = -1
bProceed = True
End If
Loop
Return iNum
End Sub
B4XComboBox seems to work fine in a dialog. Example:
B4X:
Sub Page1_Click
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, 300dip, 300dip)
p.LoadLayout("Dialog")
B4XComboBox1.SetItems(Array("aaa", "bbb", "ccc"))
Wait For (dialog.ShowCustom(p, "Yes", "No", "")) Complete (Result As Int)
If Result = xui.DialogResponse_Positive Then
Log(B4XComboBox1.SelectedIndex)
End If
End Sub
This code is called from a Button click and requires the user to definitely select a number (1 to 10) or cancel in the dialog. The code that is executed in the
button click is the following:
B4X:
Dim bOkNum As Boolean = False
Do While bOkNum = False
Wait For (GetNumber) Complete (Num As Int)
If Num = -1 Then
Return
Else
bOkNum = True
End If
Loop
I will send you a video with a private message in order to see what I see. Could it be the fact that I mix alphanumerics ("-Please select-") with numeric values (1-10) in the combo box because as I see in your code bellow you use only alphanumerics. In order to reproduce the error use the two codes (in this post and in the first), create a layout with a B4XComboBox and load it in the dialog and you will see what I see. I will send you the video anyway.
Your code:
B4XComboBox seems to work fine in a dialog. Example: