Android Question Get cursor position when focus changes

Discussion in 'Android Questions' started by hookshy, Aug 26, 2015.

  1. hookshy

    hookshy Well-Known Member Licensed 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


    Code:
    'The code below does not seem to work due to the focuschanged event that is not starting
    Sub getSelectionStart(edt As EditTextAs 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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Try to call this method with a timer or CallSubDelayed.
     
  3. hookshy

    hookshy Well-Known Member Licensed User

    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

    Code:
    Sub getSelectionStart(edt As EditTextAs Int
        
    Dim jo = edt As JavaObject
        jo.RunMethod(
    "getSelectionStart"Null)
      
    End Sub
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Your code doesn't return anything. Don't ignore the compiler warnings.
     
  5. hookshy

    hookshy Well-Known Member Licensed User

    fixed thank you
    I use edittext_click event to get mouse cursor

    Code:
    Sub getSelectionStart(edt As EditTextAs Int
        
    Dim jo = edt As JavaObject
       
    return  jo.RunMethod("getSelectionStart"Null)
     
    End Sub
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice