The Android system's inputbox dialog is useful, but it can leave the keyboard open when done. This can be an annoyance to users. To solve this, I have created a custom code module that can be used instead of the built in inputbox dialog.
First, add the EditBox code module to your project, and add the phone library that allows the EditBox code module to remove the keyboard if it remains open.
Next, we'll declare the needed variables and set up a basic activity screen.
Finally, we'll add some code to show the cInputDialog and handle events.
Note: This code module mimics the behavior of a modal dialog. Pressing the back button in the demo removes the dialog.
First, add the EditBox code module to your project, and add the phone library that allows the EditBox code module to remove the keyboard if it remains open.
Next, we'll declare the needed variables and set up a basic activity screen.
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim eb As cInputBox
Dim EditShowBtn As Button
Dim Label2 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
Activity.SetBackgroundImage(LoadBitmap(File.DirAssets,"blueback.jpg"))
End Sub
Finally, we'll add some code to show the cInputDialog and handle events.
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
If KeyCode=KeyCodes.KEYCODE_BACK AND eb.Visible=True Then
EditBox.Hide(eb)
Return True
End If
End Sub
Sub EditShowBtn_Click
Dim r As Int
r=EditBox.Show(eb,Activity,"Enter some text in the box below.","Enter text here","OK","Cancel",eb.cInputBoxEditText.INPUT_TYPE_TEXT)
If r=DialogResponse.POSITIVE Then Label2.Text=eb.Result
End Sub
'Edit box events
Sub cInputBoxBtn_click
Dim b As Button
b=Sender
EditBox.Button_click(b.Tag,eb,Activity)
End Sub
Note: This code module mimics the behavior of a modal dialog. Pressing the back button in the demo removes the dialog.
Attachments
Last edited: