Android Question Dialogs library. Bug showing the keyboard?

vecino

Well-Known Member
Licensed User
Longtime User
Hello, I am using the "Dialogs" library and I have encountered a problem.
B4A 7.30
Dialogs 4.01
I have tried it on several devices and it all happens the same.
I do not know for sure if it's a problem or that I'm using it wrong.
When displaying a dialog with ShowAsync of the numeric type.
If the keyboard button is pressed, it works fine.
If the "Ok" button of the dialog is pressed, a character keyboard is displayed, hidden, displayed a numeric keypad, hidden.
In some cases, the character keyboard is not hidden and remains on the screen.
I attach a video so you can see what I'm trying to explain.
I also attached a simple example project.
Thank you very much.
 

Attachments

  • test.zip
    6.8 KB · Views: 166

Emme Developer

Well-Known Member
Licensed User
Longtime User
Sorry but i don't understand what is the problem by viewing the video.. Is that sometimes keyboard will not close? You can use phone.hidekeyboard(activity) when dialog layout is closed
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Before the keyboard is closed, an alphanumeric keypad is displayed.
That keyboard sometimes does not close.
Anyway, why is that alphanumeric keypad displayed?
 
Upvote 0

Misterbates

Active Member
Licensed User
Happens on my setup as well. You could always switch to a CustomDialog (with a single EditText), then EditText.Enable = false after processing Result.
 
Upvote 0

Misterbates

Active Member
Licensed User
Try this ... it expects an int InputValue and returns an Int OutputValue
B4X:
Sub Test2(InputValue As Int) As ResumableSub
  
    Dim pnlWidth As Int = Min(GetDeviceLayoutValues.Width, GetDeviceLayoutValues.Height) - 32dip 'Allow margins either side
    Dim tfHeight As Int = 40dip
    Dim pnlHeight As Int = tfHeight + 32dip 'Can be adjusted to achieve a more compressed layout if needed

    Dim pnl As Panel 'Panel can be used to indicate invalid input by adding code for tf events and setting panel color or border
    pnl.Initialize("")
  
    Dim tf As EditText
    tf.Initialize("")
    tf.TextSize = 18
    tf.InputType = tf.INPUT_TYPE_NUMBERS 'Numeric keyboard
    tf.Hint = "999"
    tf.Gravity = Bit.Or(Gravity.LEFT, Gravity.CENTER_VERTICAL)
  
    If InputValue > 0 Then tf.Text = NumberFormat(InputValue, 1, 0) 'If current value is zero, keep tf.text empty to show hint

    Dim id As CustomLayoutDialog
  
    Dim sf As Object = id.ShowAsync("Test2", "Ok", "Cancel", "", Null, True)
    id.SetSize(pnlWidth + 32dip, pnlHeight + 128dip) 'Add back the width margins, plus 64dip for icon/title plus 64dip for buttons

    Wait For (sf) Dialog_Ready (dp As Panel)
    dp.AddView(pnl, 0, 0, pnlWidth, pnlHeight)
    pnl.AddView(tf, 8dip, pnlHeight - tfHeight, pnlWidth - 16dip, tfHeight)
    tf.RequestFocus 'Start with cursor in text field

    Wait For (sf) Dialog_Result(Result As Int)

    Dim OutputValue As Int = InputValue
    If Result = DialogResponse.POSITIVE Then
        If tf.Text.Length = 0 Then
            'Have seen issues with string->int when field is empty - avoid the issues.
            OutputValue = 0
        Else
            OutputValue = tf.Text
        End If
    End If
  
    tf.Enabled = False 'Close the keyboard
  
    Return OutputValue
  
End Sub
 
Upvote 0

Misterbates

Active Member
Licensed User
And it can be extended if you need a more complex dialog, or if you need to add data entry validation.
 
Last edited:
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Hello, I have a question, how can I make the keyboard display when the dialog box is displayed?
 
Upvote 0

Misterbates

Active Member
Licensed User
Hmmm. Looks like the keyboard was showing for me because I still had a call to "Test" in my code. On removing that, the keyboard didn't show - however, this version should fix that. Add a reference to the IME library, then:
B4X:
Sub Test2(InputValue As Int) As ResumableSub
   
    Dim pnlWidth As Int = Min(GetDeviceLayoutValues.Width, GetDeviceLayoutValues.Height) - 32dip 'Allow margins either side
    Dim tfHeight As Int = 40dip
    Dim pnlHeight As Int = tfHeight + 32dip 'Can be adjusted to achieve a more compressed layout if needed

    Dim pnl As Panel 'Panel can be used to indicate invalid input by adding code for tf events and setting panel color or border
    pnl.Initialize("")
   
    Dim tf As EditText
    tf.Initialize("")
    tf.TextSize = 18
    tf.InputType = tf.INPUT_TYPE_NUMBERS 'Numeric keyboard
    tf.Hint = "999"
    tf.Gravity = Bit.Or(Gravity.LEFT, Gravity.CENTER_VERTICAL)
   
    If InputValue > 0 Then tf.Text = NumberFormat(InputValue, 1, 0) 'If current value is zero, keep tf.text empty to show hint

    Dim id As CustomLayoutDialog
   
    Dim sf As Object = id.ShowAsync("Test2", "Ok", "Cancel", "", Null, True)
    id.SetSize(pnlWidth + 32dip, pnlHeight + 128dip) 'Add back the width margins, plus 64dip for icon/title plus 64dip for buttons

    Wait For (sf) Dialog_Ready (dp As Panel)
    dp.AddView(pnl, 0, 0, pnlWidth, pnlHeight)
    pnl.AddView(tf, 8dip, pnlHeight - tfHeight, pnlWidth - 16dip, tfHeight)
    Dim ShowKB As IME
    ShowKB.Initialize("")
    ShowKB.ShowKeyboard(tf)

    Wait For (sf) Dialog_Result(Result As Int)

    Dim OutputValue As Int = InputValue
    If Result = DialogResponse.POSITIVE Then
        If tf.Text.Length = 0 Then
            'Have seen issues with string->int when field is empty - avoid the issues.
            OutputValue = 0
        Else
            OutputValue = tf.Text
        End If
    End If
   
    tf.Enabled = False 'Close the keyboard
   
    Return OutputValue
   
End Sub
 
Upvote 0
Top