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. Graceful handling of SD card removal while application writing to file...


I tried to search for a solution to a general problem I am having and
came up empty.  I'm posting the following question in hopes someone
else has come across this and might know the answer and can share it.

I have an application that contains an activity and a service.  The
activity through the GUI connects to the the service and starts a
background process to write data out to the SD card.  The scenario I'm
trying to handle is if the end-user pulls the SD card out during the
background process writes being performed.  I have a broadcast
receiver in my service which is registered and does receive the event
indicating the media has been unmounted.  When my receiver receives
this event, it attempts to interrupt the background writing in order
to stop and clean up.  I'm currently using buffered I/O (not sure if
this is the reason for my problem) and so when the service detects it
needs to stop writing and clean up, it attempts to do so after closing
the open file streams.  The calls to 'close' on my buffered output
streams are failing due to the SD card being removed.  After all the
attempts have failed, the Android runtime is killing any processes
that have open file streams to the SD card and so my process (Activity
+ Service) is going away.  I could place the Activity and Service in
to separate processes such that my activity should survive but service
still punted (restarted on an as-needed basis), but I would rather see
if there's a more graceful way to handle unflushed I/O such that the
process containing my activity and service does not get reaped.

Any thoughts, ideas would be greatly appreciated.


2. Full Screen in sub-Preference Screen

I am using a PreferenceScreen with some subPreference Screens. In the
Activity I programmatically set FULL_SCREEN. This works for the main
PreferenceScreen but not for the sub-PreferenceScreens.

Is there any way to set the FULL_SCREEN for the sub-



3. Force screen orientation and avoid destroy call

4. playing sound on active call

5. Custom list adapter using SQL and line-specific icons

6. Additional fonts for use with Webkit

7. How i get the Selected item from the list Adapter.