Android Question App crashes on long-click on Xiaomi devices

lare

Member
Is there a possibility to disable the long-click event on the 'EditText' control?
Because when I have text in it that is clickable, when a short click is made, everything works fine, but when a long-click is made, the application on Xiaomi devices crashes with the following message:
B4X:
You have clicked on word: 1
You have clicked on word: 2
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.widget.Editor$SelectionModifierCursorController.getMinTouchOffset()' on a null object reference
    at android.widget.Editor.touchPositionIsInSelection(Editor.java:1091)
    at android.widget.Editor.performLongClick(Editor.java:1212)
    at android.widget.TextView.performLongClick(TextView.java:10916)
    at android.view.View.performLongClick(View.java:6368)
    at android.view.View$CheckForLongPress.run(View.java:24776)
    at android.os.Handler.handleCallback(Handler.java:794)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:176)
    at android.app.ActivityThread.main(ActivityThread.java:6651)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)

I've attached a small demo project and video so you can see what's going on. Thank you!!!
 

Attachments

  • skrolanje.zip
    67.8 KB · Views: 113

zed

Active Member
Licensed User
I tested your code on a Xiaomi mi 10. There is no problem.
The click works correctly and the lonClick does absolutely nothing.
Maybe try this
B4A:
Private Sub cs_LongClick
    Return
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
It works on my Samsung running Android 12. Event single and also longclick.
Both raises the click-sub though.
Guess there is no LongClick-Listener added in the bbcodeview.
 
Last edited:
Upvote 0

lare

Member
@zed and @DonManfred thank you for your replies.

I tested on
Xiaomi Redmi 5 Plus with Android 8.1 MIUI Global 11,
Xiaomi Redmi 10c with Android 11 MIUI Global 13 and it gives me the same error on both devices.
When I tested it on two older LG phones, everything worked fine. And it works perfectly fine on the emulator.
I tried adding this code you suggested
Private Sub cs_LongClick...
...but it had no effect, it seems that csBuilder does not have an event for LongClick...the application never enters that part of the code. It looks like users of other platforms have also faced the same error for Xiaomi devices https://stackoverflow.com/questions...widget-editorselectionmodifiercursorcontrolle so I will continue to investigate the issue….
 
Upvote 0

lare

Member
I was able to solve the problem using reflection.
I added the following code and it worked :)

B4X:
Dim reflector1 As Reflector
reflector1.Target = EditText1
reflector1.SetOnLongClickListener("EditText_LongClick")

Sub EditText_LongClick(objectViewTag As Object) As Boolean
    Try
        Log("long clikc")
        Return True
    Catch
        Log(LastException)
    End Try
End Sub
 
Upvote 0
Top