Android Question SMMRichTextEditor


Active Member
Licensed User
Longtime User
Hello, this library seems to be very useful.

I tried to use it to develop custom controls which led me directly to a problem:

I am looking for a way to read the XY cursor position in (rte As SMMRichEditor)
Something similar to the GetXYCursor function:

- it would allow me to scroll the edit field (rte) in programming, so that the view of the virtual keyboard
does not cover the cursor when entering the field edit mode (rte).

Expected: x and y coordinates, view in pixels, cursor in SMMRichEditor.

Private Sub GetXYCursor(edt As B4XFloatTextField) As Int()
Private joEditText, joLayout As JavaObject
Private xy(4) As Int
#Region NEW CHANGES in the project -----------
joEditText = edt.TextField
PaddingLeft = joEditText.RunMethod("getPaddingLeft", Null)
PaddingTop = joEditText.RunMethod("getPaddingTop", Null)
ScrollY = joEditText.RunMethod("getScrollY", Null)
Pos = joEditText.RunMethod("getSelectionStart", Null)
joLayout = joEditText.RunMethod("getLayout", Null)

#Region 'show line(bottom): the last visible line of text ---------------------------
Line = joLayout.RunMethod("getLineForOffset", Array As Object(txtField1.Text.Length))
LineCount = joLayout.RunMethod("getLineBottom", Array As Object(Line))
#End Region -------------------------------------------------------------------------

Line = joLayout.RunMethod("getLineForOffset", Array As Object(Pos))
LineBaseline = joLayout.RunMethod("getLineBaseline", Array As Object(Line))
LineBottom = joLayout.RunMethod("getLineBottom", Array As Object(Line))
LineTop = joLayout.RunMethod("getLineTop", Array As Object(Line))
xy(0) = joLayout.RunMethod("getPrimaryHorizontal", Array As Object(Pos)) + PaddingLeft
xy(1) = LineBaseline + PaddingTop - ScrollY 'base line
xy(2) = LineTop + PaddingTop - ScrollY 'top of the line
xy(3) = LineBottom + PaddingTop - ScrollY 'text bottom line
Return xy
#End Region ----------------------------------
End Sub


  • Screenshot_20220505-151949.png
    42 KB · Views: 66
Last edited: