
This example uses inline Java with JavaObject to allow creating custom context menus when the user selects text.
To use it in your project you need to add the inline Java code and implement this method:
B4X:
Sub ContextMenu_Create(ActionMode As JavaObject, FocusedView As View)
Dim menu As JavaObject = ActionMode.RunMethod("getMenu", Null)
menu.RunMethod("clear", Null)
Dim event As Object = menu.CreateEvent("android.view.MenuItem.OnMenuItemClickListener", "ContextMenuClick", True)
For Each s As String In Array("Set As Title", "Delete") 'menu items here
menu.RunMethodJO("add", Array(s)).RunMethod("setOnMenuItemClickListener", Array(event))
Next
Wait For ContextMenuClick_Event (MethodName As String, Args() As Object)
Dim MenuItem As JavaObject = Args(0)
Dim title As String = MenuItem.RunMethod("getTitle", Null)
Log(title & " was clicked!") '<---- do what ever you like with the click!!!
ActionMode.RunMethod("finish", Null)
End Sub
Extracting the selected text depends on the view. EditText.SelectionLength property is currently missing. It will be available in the next update.