Sub Globals
    Private edtTest As EditText
End Sub
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    
    'adds a Click listener
    'as long as the EditText has the focus, the FocusChanged event is not raised, therefore the Click event
    Private refEditText As Reflector
    refEditText.Target = edtTest
    refEditText.SetOnClickListener("edtTest_Click")
    edtTest.Text = "This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text."
End Sub
'used for the first click, sets the focus and selects the cursor position
Private Sub edtTest_FocusChanged (HasFocus As Boolean)
    SelectLine
End Sub
'used for subsequent clicks when the EditText has the focus
Private Sub edtTest_Click(View As Object)
    SelectLine
End Sub
Private Sub SelectLine
    'SelectionStart = text cursor position
    'LineIndex = index of the line where the cursor is positioned
    'LineStart = text cursor position of the first character in the line
    'LineVisibleEnd = text cursor position of the last visible character in the line
    Private SelectionStart, LineIndex, LineStart, LineVisibleEnd As Int
    Private joEditText, joEditTextLayout As JavaObject
    
    joEditText = edtTest
    joEditTextLayout = joEditText.RunMethod("getLayout", Null)
    
    SelectionStart = joEditText.RunMethod("getSelectionStart", Null)
    LineIndex = joEditTextLayout.RunMethod("getLineForOffset", Array As Object(SelectionStart))
    LineStart = joEditTextLayout.RunMethod("getLineStart", Array As Object(LineIndex))
    LineVisibleEnd = joEditTextLayout.RunMethod("getLineVisibleEnd", Array As Object(LineIndex))
    joEditText.RunMethod("setSelection", Array As Object(LineStart, LineVisibleEnd))
End Sub