Android Question Problem disabling softkeyboard with B4XPages

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Converting from an Activity based project to B4XPages and sofare so good.
Have a problem though implementing my custom keyboard, which works perfectly fine in the old project.

The error I get is this:

Error occurred on line: 9754 (B4XMainPage)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:1057)
at b4a.exampleljjll.b4xmainpage$ResumableSub_SetPage.resume(b4xmainpage.java:1453)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1772)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8741)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:336)
at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:285)
... 24 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
... 25 more
Caused by: java.lang.RuntimeException: Method: disableSoftKeyboard not found in: b4a.exampleljjll.main
at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:363)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:120)
at b4a.exampleljjll.b4xmainpage._setedittextinput_type(b4xmainpage.java:20793)
at b4a.exampleljjll.page0._setfindpatientcustomkeyboard(page0.java:970)
at b4a.exampleljjll.page0._loadlayout(page0.java:220)
... 27 more
** Activity (main) Pause event (activity is not paused). **
** Service (starter) Destroy (ignored)**

When running this code from B4XMainPage:

B4X:
Sub Class_Globals

    Public NativeMe As JavaObject

'etc.
End Sub

#IF JAVA
    import android.widget.EditText;
    import android.os.Build;
    import android.text.InputType;

 public void disableSoftKeyboard(final EditText v) {
    if (Build.VERSION.SDK_INT >= 11) {
        v.setRawInputType(InputType.TYPE_CLASS_TEXT);
        v.setTextIsSelectable(true);
        v.setShowSoftInputOnFocus(false);
     } else {
        v.setRawInputType(InputType.TYPE_NULL);
        v.setFocusable(true);
     }
}

 public void enableSoftKeyboard(final EditText v, int iKeyBoardType) {
    if (Build.VERSION.SDK_INT >= 11) {
        v.setRawInputType(iKeyBoardType);
        v.setTextIsSelectable(true);
        v.setShowSoftInputOnFocus(true);
     } else {
        v.setRawInputType(iKeyBoardType);
        v.setFocusable(true);
     }
                     
}
#END IF

Sub SetEditTextInput_Type(bDoCustomKeyboard As Boolean, oEditText As  EditText, iKeyBoardType As Int, bHandleAction As Boolean)
    
    If NativeMe.IsInitialized = False Then
        NativeMe.InitializeContext
    End If
    
    Log("SetEditTextInput_Type, oEditText.Tag: " & oEditText.Tag) 'this shows fine, with the right Tag
    
    If bDoCustomKeyboard Then
        NativeMe.RunMethod("disableSoftKeyboard", Array As Object(oEditText)) '<<<<< java.lang.reflect.InvocationTargetException
    Else
'etc. code not relevant to the mentioned problem
    
End Sub

I call SetEditTextInput_Type from another page, after the layout has been loaded.
I also tried to run the same code from the page where the layout was loaded, but exactly same problem.

Any idea what the problem could be here?

RBS
 

agraham

Expert
Licensed User
Longtime User
Try putting the Java and SetEditTextInput_Type in the Main module and not B4XMainPage. Note that the error is

Caused by: java.lang.RuntimeException: Method: disableSoftKeyboard not found in: b4a.exampleljjll.main

Because SetContext identifies the context of Main, the only activity in a B4XPages app, it is looking in Main for disableSoftKeyboard.

B4XMainPage is a class and I think you my be able to declare the Java there if you declare disableSoftKeyboard static and initialise NativeMe with InitializeStatic and "B4XMainPage", but I'm not 100% sure.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
How do I refer to Main?
I thought simply Main. would do it but that is not so.
The other thing is that I thought that we should not put any extra code in Main.
Maybe this should be an exception.
What would the full Java code be?

RBS
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
You don't need to, InitialiseContext does it if located in Main.

Possibly

What you already have. Just move it.
>> You don't need to, InitialiseContext does it if located in Main.

But if SetEditTextInput_Type is put in Main as well (as you suggested), then how do I refer to that Sub then?

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Make it public and call Main.SetEditTextInput_Type.
I did that (in Page0)

B4X:
Main.SetEditTextInput_Type(cMP.bCustomKeyboard, edtID, Enums.eKeyboardStates.Numeric, True)

But get:
unknown member: SetEditTextInput_Type

Actually what at least gives me no error is putting just the Java code in Main and leave the rest the same.
No custom keyboard popping up yet, but that might be a problem somewhere else.

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
With the Java code in Main and SetEditTextInput_Type in B4XMainPage, I managed to get my custom keyboard popping up now.
Further work to be done as it has no buttons, but I think on the right track now.
Currently the keyboard loads to the various roots of the various pages, but I wonder now if it is still possible to load it to the old
activity as in Main?

RBS
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…