Android Question Get cursor position when focus changes

hookshy

Well-Known Member
Licensed User
Longtime User
I am trying to find out how to get the cursor position when the user clicks inside a edittext!
with this it will help me read the word inside the edit text that the user focused on it in order to modify it ...but I want the cursor position before any other text inside to change


B4X:
'The code below does not seem to work due to the focuschanged event that is not starting
Sub getSelectionStart(edt As EditText) As Int
    Dim jo = edt As JavaObject
    jo.RunMethod("getSelectionStart", Null)
End Sub
Sub editvorbe_FocusChanged (HasFocus As Boolean)

Dim position As Int
position=getSelectionStart(editvorbe)
ToastMessageShow(position,True)
  
End Sub

'the sub below works but does not help at all because
' it returns the cursor position only if the user does  modify the word inside by adding 'letter or deleting which actually make the word that was focused with the cursor change
'and I will not read what was the word that was modified

Sub editvorbe_TextChanged (Old As String, New As String)

Log(editvorbe.SelectionStart)

End Sub
 

hookshy

Well-Known Member
Licensed User
Longtime User
Try to call this method with a timer or CallSubDelayed.
I have tried ...I guess the theory is correct but it seems that the code might be wrong ?

Is this code corect ? because it returns always 0

B4X:
Sub getSelectionStart(edt As EditText) As Int
    Dim jo = edt As JavaObject
    jo.RunMethod("getSelectionStart", Null)
  
End Sub
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
fixed thank you
I use edittext_click event to get mouse cursor

B4X:
Sub getSelectionStart(edt As EditText) As Int
    Dim jo = edt As JavaObject
   return  jo.RunMethod("getSelectionStart", Null)
 
End Sub
 
Upvote 0
Top