Android Question How to avoid double-tap contextual menù in EditText ?

robotop

Member
Licensed User
Longtime User
Hi all.
I have an EditText view and some buttons on a simple App.

The buttons have the purpose to copy / paste ALL the text in the EditText to / from the clipboard.

If I double-tap the EditText view, a default contextual menù appears with "Select All, Copy, Cut, Paste".

Is there a way to filter out the double-click AND ANY OTHER event that selects a piece (or all) of the text in the EditText view ?

I need to handle the text selection only with my own buttons.

Thank you in advance for your help.

Edited: why the system's "cut and paste" removes the existing CRLF from a copied text to a pasted text ? If I copy all the text in the view with the contextual menu "select all" + "copy" and after that (on the same EditText) I do "Paste" at end of actual text, I have a long line appended without any CRLF...
 
Last edited:

robotop

Member
Licensed User
Longtime User
Thank you, Erel, but I can't run the example in my version of B4A.

Can you supply another that can be executed in B4A V3.80 ?

At this moment I'm trying to solve the problem using a webview with html textarea inside, but it's a dirty job.

Anyway, do you have an answer to the second question about the CRLF lost during the copy and past of the system contextual menu ?

Thanks a lot.
 
Upvote 0

robotop

Member
Licensed User
Longtime User
The CRLF problem seems to be related with the input type. I have a multiline EditText with softkeyboard set as ' NUMBER'.
I used this code to intercept the newline from keyboard (it doesn't work by itself)
B4X:
Sub IME_HandleAction As Boolean
Dim k As Int
Dim s As String

    k = edtDay.SelectionStart
    If k >= 0 Then ' if cursor exists
        s = edtDay.Text.SubString2(0, k)
        s = s & CRLF
        s = s & edtDay.Text.SubString(k)
        edtDay.Text = s
        edtDay.SelectionStart = k +1
'        ToastMessageShow(k, False)
        Return True 'Consume the event; the keyboard will not be closed
    Else
        Return False 'will close the keyboard
    End If
End Sub
In this way I can add new lines to the EditText, but if I use the default copy and paste tool, the CRLF is NOT copied.

About the example you suggested, I'm trying to adapt it to my B4A version.
Thanks.
 
Upvote 0

robotop

Member
Licensed User
Longtime User
About the context menu: I can't open the file 1.bal (it gives an error for file type=12) with my b4a version (it's a little bit frustrating).

Looking inside such file with one Hex Editor, I see that there are just two views: EditText1 and WebView1.
So I created a new file 1.bal with such views, and this can be read by my b4a version.

I also changed the 'wait for' (that is unavailable in my version) with a do..loop including a DoEvents (I know, it's deprecated now), that breaks when ContextMenuClick_Event changes a boolean flag.

The program compiles without errors and runs on my device.
The contextual menu is fired when I make a longclick on one of the words in the webpage showed.
This happens only one time...
Exiting, then restarting the App, produces an "application not responding" error.

It's not so clear to me who starts the "ContextMenu_Create(ActionMode As JavaObject, FocusedView As View)".
It's the longclick on the webview text element ? edit: onActionModeStarted(ActionMode mode) in Java code ?

Why I don't see "Set As Title" and "Delete" contextual menus if I longclick a word of the EditText1 view ?

Sorry for the huge quantity of questions. I'm trying to understand how it works.
Thanks.
 
Last edited:
Upvote 0

robotop

Member
Licensed User
Longtime User
Ok, I modified the source and now it works better.
I have my own contextual menu when I longclick one of the words in the WebView, but I still have the system contextual menu (I hate it) if I longclick the EditText view.
So, it was an interesting experiment, but I haven't solved my problem...

note: clicking every one of my menu items, produces the "Application stopped in a wrong way" error. I think it depends on my "translation" of the original code (may be event array ?)
B4X:
Installing file.
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
java.lang.IllegalArgumentException: result has type boolean, got java.lang.String
    at $Proxy3.onMenuItemClick(Unknown Source)
    at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:154)
    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:909)
    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:899)
    at android.widget.ActionMenuView.invokeItem(ActionMenuView.java:623)
    at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:141)
    at android.view.View.performClick(View.java:4848)
    at android.view.View$PerformClick.run(View.java:20300)
    at android.os.Handler.handleCallback(Handler.java:815)
    at android.os.Handler.dispatchMessage(Handler.java:104)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5690)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:963)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:758)
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
That example will not work with B4A v3. There are many things in that example that are not supported by B4A v3.
B4A, Android OS and Android SDK have evolved a lot since 2014. Most of the new examples (at least the more complex ones) will not work with your version.

Anyway, do you have an answer to the second question about the CRLF lost during the copy and past of the system contextual menu ?
No. It is handled completely by the OS.
 
Upvote 0

robotop

Member
Licensed User
Longtime User
Ok, Erel. I lost my battle against windmills. I'm going to install Win7 (or newer !).
Please, be prepared to receive a request for a new license for B4A, B4i plus an additional ticket to Lourdes.
Many thanks for your help. Bye :)
 
Last edited:
Upvote 0
Top