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. Screen touches during game

Hi all.

What's the best way of intercepting screen touches and coords during a
game loop? At this point, I don't have a View from my main.xml file,
so the normal OnTouchEvent doesn't apply, as far as I can tell.

What's the usual procedure for this?



2. Using sessionStorage in a webview

Hi all,

I am trying to set a flag for the current session in the webview. I
enabled the DOM storage API:


In my HTML page, loaded from the assets directory, I then execute a
small piece of javascript like this:

                        if (!sessionStorage.flag)
                                        //do stuff once per session
                                        sessionStorage.flag = true;
                                //do nothing

Problem: the //do stuff once per session section is always entered, it
seems the flag is set but each orientation change reloads the complete
HTML page and all the session state is completely lost.

I wanted to use the flag to execute a piece of code once, and even if
the user turns the device, (in which the HTML page seems to be
reloaded, for whatever reason), not execute the code again.

Any ideas?
Is this just broken becaus I load the HMTL resource from the local
package, from the assets directory?



3. Orientation sensor problem.

4. Job Opening for Mobile Developer in Rockland County, NY - Northern NJ / Westchester / NYC

5. OnSharedPreferenceChangeListener never receives callback

6. Switching Signing Keys

7. Debugging with DDD