Android Question Input Dialog terminates when using suggestions

Didier9

Well-Known Member
Licensed User
Longtime User
This is the code (straight from an example from the IDE):
B4X:
Sub Button2_Click
    Dim email As String
    id.InputType = id.INPUT_TYPE_TEXT
    id.Input = ""
    id.Hint = "somebody@gmail.com"
    id.HintColor = Colors.ARGB( 196, 255, 140, 0 )
 
    Dim sf As Object = id.ShowAsync( "Enter email address", "Test", "Yes", "Cancel", "No", Null, False )
    Wait For( sf ) Dialog_Result( Result As Int )
    If Result = DialogResponse.POSITIVE Then
        ' Check if value is empty
        If id.Input = "" Then
            ToastMessageShow( "No email, cancelled", True )
            IME.HideKeyboard
            Return
        Else
            email = id.Input
            Log( email )
        End If
    Else
        Log( Result )
        IME.HideKeyboard
        Return
    End If
Log( "done" )
End Sub

If i enter the email address manually, all is good.



If I click on one of the suggestions (I guess they come from Android itself), the dialog closes but none of the following code is executed, it seems to just return to main.

This is on a Pixel 3 running Android 11 but I tried on other devices and it does the same thing.
I also tried the non-async version and it does the same thing.
 

Attachments

  • TestInputDialog.zip
    4.7 KB · Views: 234
Last edited:

JohnC

Expert
Licensed User
Longtime User
Are any log messages posted?
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
Use input template from B4XDIALOG !

I was sure someone was going to propose that. I appreciate the suggestion, but this seems like a significant waste of my time (assuming I can get the Input Dialog working eventually). These other dialogs look different and require a significant amount of learning and troubleshooting, at least for me, which I really don't have time for at the moment.

If the Input Dialog is obsolete/broken, then it should not be part of the IDE. As long as it is and is documented (with code example), I expect it to offer basic functionality (including handling suggestions since Android is hell-bent on offering those), which is all I need. I do not need icons or graphics or rainbow colored background, I just need a simple input box where I put my email.

I have attached the project containing the offending code to the original post. It is extremely short
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
If the Input Dialog is obsolete/broken, then it should not be part of the IDE
It is not part of the IDE. It is a useful third party library.

I wasn't able to reproduce it as my test device didn't autocomplete the emails.

You can try it with B4XDialog. It is quite simple:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private dialog As B4XDialog
    Private InputTemplate As B4XInputTemplate
End Sub

Public Sub Initialize
   
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    dialog.Initialize(Root)
    InputTemplate.Initialize
    SetLightThemeDialog(dialog)
    SetLightThemeInput(InputTemplate)
End Sub

Sub Button2_Click
    Dim sf As Object = dialog.ShowTemplate(InputTemplate, "Yes", "No", "Cancel")
    Dim id As EditText = InputTemplate.TextField1
    id.InputType = 0x00000020 'EMAIL
    id.Text = ""
    id.Hint = "somebody@gmail.com"
    id.HintColor = Colors.ARGB( 196, 255, 140, 0 )
    InputTemplate.RegexPattern = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
    InputTemplate.lblTitle.Text = "Enter email address"
    Wait For (sf) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Log(id.Text)
    End If
    Log( "done" )
End Sub

Private Sub B4XPage_CloseRequest As ResumableSub
    If dialog.Visible Then
        dialog.Close(xui.DialogResponse_Cancel)
        Return False
    End If
    Return True
End Sub

Private Sub SetLightThemeInput(input As B4XInputTemplate)
    Dim TextColor As Int = 0xFF5B5B5B
    input.TextField1.TextColor = TextColor
    input.lblTitle.TextColor = TextColor
    input.SetBorderColor(0xFFC3C3C3, xui.Color_Red)
End Sub


Private Sub SetLightThemeDialog(dialog2 As B4XDialog)
    dialog2.BackgroundColor = xui.Color_White
    dialog2.ButtonsColor = xui.Color_White
    dialog2.BorderColor = xui.Color_Transparent
    dialog2.ButtonsTextColor = 0xFF007DC3
End Sub

It also offers nice features such as regex validation and it is cross platform.

 
Last edited:
Upvote 0

agraham

Expert
Licensed User
Longtime User
Calm down! A little bit less aggression would be appreciated.
I wrote the Dialogs2 library and I can't reproduce this as my devices don't show suggestions in this case.
Try adding the following value to InputType.

B4X:
id.InputType = id.INPUT_TYPE_TEXT + 0x00080000 ' TYPE_TEXT_FLAG_NO_SUGGESTIONS.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
Thank you Erel and Agraham.

I am sorry for the tone of my reply but so many times reading through the forum when someone reports that something is not working as expected, they are told to use something else with no explanation as to why the original approach did not work.
If I do not know why the original approach did not work, even if it's something I did wrong, how do I know the new one will work?
How much time am I going to spend trying the new way to find out if it fixed the problem or not?
How am I not going to make a similar "mistake" (of using a documented feature the way the example suggests) again?
I have spent hours trying to understand why this simple control now fails, when it was working when I wrote the app several moons ago. I was so sure I could find my mistake I did not even think of asking the forum.

The added frustration with Android in general with so many features going away requiring code rewrite when the old code was working just right.

For reference, I still run (and compile) Visual Basic 6.0 code on Windows 10. The tool is dated 1998. I appreciate that Microsoft went to great length to make sure the old software was not broken through so many upgrades of the OS. I wish Google had as much concern.

The app I am working on is the main app I use to track my expenses. I have been using extensively it for several years as I use it to submit my paperwork to the accountant. It saves me A TON of time and money, as the accountant does not have to spend so much time tracking every expense and putting it in the right column.

This year I decided the app needed some increased functionality and it's like I opened a rabbit hole. So many things stopped working when I changed the target SDK.
I just wanted to make my changes, I was not planning on having to make so many other changes I did not know I needed because of Android. I know it's naïve of me but really I was not planning on spending so much time, I have other stuff piling up now.

The other issue is that the new input box looks different. I use it in many places so now I have to chase all those and change them too or it will look funny.

Sorry for the rant, and than you again. I will try Erel's method since it looks like it's my only recourse at this time.
Agraham, the Dialog2 library is great, I use multiple functions out of it and so far that's the only issue, and it's a new one as it was working.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
Agraham's suggestion did fix the problem, but it's a lot like throwing the baby with the bath water
Thank you, it will do for now.

Didier
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…