Can't get cursor position from InputConnection

by nattster » Fri, 20 May 2011 09:30:36 GMT

Sponsored Links
 I'm developing an Input Method. 
I'd like to change cursor position with 
*InputConnection.setSelection< #setSelection(int,

This method allows me to set absolute position of cursor.
But what I want is to move cursor relatively from current position.
(e.g. Move left 3 characters from current position)

I can't find method to get current cursor position.
Currently, I got this hack:

    InputConnection conn;
    CharSequence seq = conn.getTextBeforeCursor(1000, 0); 
    // will get as much characters as possible on the left of cursor

    int cursor_pos = seq.length();

Is there any better way to do this?
Should we introduce new method to InputConnection, i.e. getSelectionStart?


Other Threads

1. Save Cyanogenmod Petition

Save Cyanogenmod. Download the Save Cyanogenmod Petition application from 
market,and put your comment on the market page.

Google Groups "Indonesian Android Community [id-android]" group.

To post to this group, send email to

To request to subscribe to this group, please visit the following page:

2. How to delete file when file is created by another app

> I have this problem. Two apps: app_a and service_s.

Why two apps?

There is no /tmp in Android.

You would need to also set permission on the directory to 666 -- in Linux,
deleting a file is considered an operation on the directory.

Bear in mind that by doing this, any application on the system can read
and manipulate files in this directory. There is likely a more secure
means of data sharing than this that your apps can use. Or, have them both
be a single app.

Mark Murphy (a Commons Guy)
Android App Developer Books:


3. VideoRecorder and VideoPlayer

4. enable the ethernet interface on embinux kernel

5. where to know that the apps selected for ADC2?

6. Android Port based on 2.6.31 kernel on Zoom-2 board

7. How to force soft keyboard to be visible?