Android Tutorial Handle the soft keyboard with the IME library

Status
Not open for further replies.

dlfallen

Active Member
Licensed User
OK, so I have:

B4X:
Sub Query1_Click
QueryPnl.Visible = True
QueryTxt.RequestFocus
CallSubDelayed(Me, "ShowKB")
End Sub

Sub ShowKB
Dim IME As IME
IME.ShowKeyboard(QueryTxt)
End Sub
No errors on compiling, but no keyboard either.
 

dlfallen

Active Member
Licensed User
No it does not help. In fact I started with all of the statement in ShowKB and then moved them out when that did not woek.
 

dlfallen

Active Member
Licensed User
After much trial and error, I found a solution by using DoEvents.
B4X:
Sub ShowKB
DoEvents
Dim IME As IME
DoEvents
IME.ShowKeyboard(QueryTxt)
End Sub
Both DoEvents are needed to make this work. The placement of the DoEvents seems odd. I have tried various placement of the two Doevents within the code and only this one seems to work. A single DoEvents does not work regardless of where it is placed.

Whatever works, I guess, but this is not the kind of insight I can build on in the future.
 

Rusty

Well-Known Member
Licensed User
Is there a way to force the keyboard microphone to appear (and be enabled)? my keyboards do not show this.
Thanks,
Rusty
 

derez

Expert
Licensed User
Am I right that the only way to input a negative decimal number is by a full text keyboard ?
Even if the minus symbol is visible in some devices, it is not active in number or decimal kbd.
The IME filters the keys action but they are still there.
 

mrazamerchant

Member
Licensed User
HI, does ime.showkeyboard works on activity create event? What I am looking for is on click of a button I am loading a new activity which has a edittext, I need to load the keyboard so user can start typing. Right now the focus is on edittext but keyboard doesn't show up, user has to click on edittext to bring the keyboard.

Sub Activity_Create(FirstTime AsBoolean)
Activity.LoadLayout("drglist")
IME.Initialize("IME")
IME.AddHandleActionEvent(txtSearchBrand)
Activity.SetBackgroundImage(LoadBitmap(File.DirAssets, "grey.jpg"))
IME.ShowKeyboard(txtSearchBrand)
End Sub
 
Last edited:

Rick Harris

Well-Known Member
Licensed User
I have been struggeling with the IME for hours. I simply wanted to push the entire activity upwards to enter something in an edittext at the bottom of the screen. The IME keyboard was a nuisance because it kept covering the edittext.
The solution was NOT to add the command from thread-114 to the Manifest:
B4X:
 SetActivityAttribute(main, android:windowSoftInputMode, adjustResize|stateHidden)
but in stead this command:
B4X:
 SetActivityAttribute(main, android:windowSoftInputMode, adjustPan|stateHidden)
(so use "adjustPan" in stead of "adjustResize")

Furthermore, do not add IME.AddHeightChangedEvent to the activity nor the IME_HeightChanged event because that seems to inhibit the adjustPan feature!

Also this thread is no longer valid: http://www.basic4ppc.com/android/fo...appears-on-top-of-edit-text.12136/#post-68090 because the format for additions to the manifest has changed and the suggestion to "Don't forget to check Do Not Override Manifest File" is now obsolete.
 
Last edited:

johnaaronrose

Active Member
Licensed User
When an activity in my app runs in portrait mode (with its own variant), there is sufficient room for the keyboard to display without any of the views being 'hidden'. However in landscape mode (with its own variant), the keyboard appears and all the views are 'hidden' (due to the box for entering an EditText value being much higher than its box on the screen). The layout in this case consists of a 'line' with one Label & a button, followed by a line with 3 Labels, followed by a line with 3 EditTexts. A screen shot is attached from the Abstract Designer & a screenshot showing the situation at runtime.
PS I'm not currently using the IME.AddHeightChangedEvent but would happy to use it in order to solve this problem if knew how to do it.
 

Attachments

johnaaronrose

Active Member
Licensed User
By default the keyboard appears this way in landscape orientation.

You can disable this behavior with this code:
B4X:
Dim jo As JavaObject = EditText1.Text
jo.RunMethod("setImeOptions", Array As Object(268435456)) 'IME_FLAG_NO_EXTRACT_UI
When I used the code below, I got "java.lang.RuntimeException: Method: setIMEOptions not found in: java.lang.string:
B4X:
Dim JO As JavaObject
JO = edtMap.Text
JO.RunMethod("setImeOptions", Array As Object(268435456)) 'IME_FLAG_NO_EXTRACT_UI
I have the Java Object library included so no compilation errors. Could the exception be due to running the app on a Gingerbread phone?

Webpage for URL https://developer.android.com/reference/android/view/inputmethod/EditorInfo.html
states for IME_FLAG_NO_EXTRACT_UI that "The part of the UI visible to the user may not be responsive to touch because the IME will receive touch events, which may confuse the user; use IME_FLAG_NO_FULLSCREEN instead for a better experience. Using this flag is discouraged and it may become deprecated in the future. Its meaning is unclear in some situations and it may not work appropriately on older versions of the platform.". So would it be better to use IME_FLAG_NO_FULLSCREEN instead?

Also, which flag should I use to 'reset' the behaviour due to the above flag? The reason I ask this is that I have a sub named ResizeViews (called in Activity_Create & Activity_Pause) which does as its name suggests using SetLayout commands with different ones depending on which 'orientation' (i.e. portrait or landscape) is current. That is where I put the above 'JavaObject' code.
 

johnaaronrose

Active Member
Licensed User
My mistake. It should be Dim jo As JavaObject = EditText1 (not .Text).
OK now for landscape input except that keyboard now shows Done rather than Next. Also, after clicking Done, keyboard is hidden (as executed by code) but there is no automatic progression (as requested by code shown below in IME_HandleAction event's code for the edtMap EditText):
B4X:
Dim R As Reflector
    R.Target = edtMap
  R.RunMethod2("setFocusable", TrueFalse, "java.lang.boolean")
  R.RunMethod2("setFocusableInTouchMode", TrueFalse, "java.lang.boolean")
So should I use IME_FLAG_NO_FULLSCREEN rather than IME_FLAG_NO_EXTRACT_UI due to the following:
Webpage for URL https://developer.android.com/reference/android/view/inputmethod/EditorInfo.html
states for IME_FLAG_NO_EXTRACT_UI that "The part of the UI visible to the user may not be responsive to touch because the IME will receive touch events, which may confuse the user; use IME_FLAG_NO_FULLSCREEN instead for a better experience. Using this flag is discouraged and it may become deprecated in the future. Its meaning is unclear in some situations and it may not work appropriately on older versions of the platform."

Also, which flag should I use to 'reset' the behaviour due to the above flag? The reason I ask this is that I have a sub named ResizeViews (called in Activity_Create & Activity_Pause) which does as its name suggests using SetLayout commands with different ones depending on which 'orientation' (i.e. portrait or landscape) is current. That is where I put the above 'JavaObject' code.
 
Status
Not open for further replies.
Top