How do you get the end of a selection in EditBox?

ondesic

Active Member
Licensed User
Longtime User
I noticed that there is a selectionStart property, but how do you get the end of the selection?

Thanks
 

Omar

Member
Licensed User
Longtime User
Hello Erel,

I tried utilizing this code but this does not return the cursor to the end property. I logged the resulting values and no matter what the length of the EditText field is, this sub always returns 0.

Can you please assist.


Omar


You can use this code to get the selection end property with the reflection library:
B4X:
Sub GetSelectionEnd(txt As EditText) As Int
   Dim r As Reflector
   r.Target = txt
   Return r.RunMethod("getSelectionEnd")
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I tried it with this code and it works correctly:
B4X:
Sub Globals
   Dim et As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
   et.Initialize("et")
   Activity.AddView(et, 0, 0, 200dip, 100dip)
End Sub

Sub et_TextChanged (Old As String, New As String)
   Log(GetSelectionEnd(et))
End Sub

Sub GetSelectionEnd(txt As EditText) As Int
    Dim r As Reflector
    r.Target = txt
    Return r.RunMethod("getSelectionEnd")
End Sub
Sub Activity_Click
   Log(GetSelectionEnd(et))
End Sub
 
Upvote 0

Omar

Member
Licensed User
Longtime User
Thank you Erel.

I will re-check it with your code.



Omar


I tried it with this code and it works correctly:
B4X:
Sub Globals
   Dim et As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
   et.Initialize("et")
   Activity.AddView(et, 0, 0, 200dip, 100dip)
End Sub

Sub et_TextChanged (Old As String, New As String)
   Log(GetSelectionEnd(et))
End Sub

Sub GetSelectionEnd(txt As EditText) As Int
    Dim r As Reflector
    r.Target = txt
    Return r.RunMethod("getSelectionEnd")
End Sub
Sub Activity_Click
   Log(GetSelectionEnd(et))
End Sub
 
Upvote 0
Top