Android Question InputDialog turn me crazy

marcick

Well-Known Member
Licensed User
Longtime User
Look to the code below:

If you press cancel everything is ok.
If you press OK with a text.lenght <5 the input dialog is shown again as expected. But if after this you press cancel again, you see "completed".
What's wrong in my code ?

B4X:
Sub Button1_Click
    Dim id As InputDialog
    id.Show("Inserirt name","Test","Ok","Cancel","",Null)
    If id.Response=DialogResponse.CANCEL Then
        Return
    End If
    Dim a As String=id.Input
    Log("text lenght=" & a.Length)
    If a.Length<5 Or a.Length>40 Then Button1_Click
    Log("completed")
End Sub
 

stevel05

Expert
Licensed User
Longtime User
When you press cancel on subsequent calls, the process returns to the line that called the Button1_Click sub, so then immediately runs the line that logs completed.

It would be better to put this in a loop:

B4X:
Sub Button1_Click
    Dim id As InputDialog
    Dim a As String
    Do While a.Length < 5 Or a.Length > 40
        id.Show("Insert name","Test","Ok","Cancel","",Null)
        If id.Response=DialogResponse.CANCEL Then
            Return
        End If
        a =id.Input
        Log("text length=" & a.Length)
    Loop
    Log("completed")
End Sub
 
Upvote 0
Top