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< http://developer.android.com/reference/android/view/inputmethod/InputConnection.html #setSelection(int,
 
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. Theme.Dialog for PreferenceScreen child does not work

I can't help you off-hand with the problem, but for what it's worth
preferences really aren't intended to be used with a dialog theme.  Actually
I would stay away from the dialog theme for all but very simple things (like
alerts), since the border takes so much space away from your UI.

Of course in general I don't like dialogs. :)








-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support.  All such questions should be posted on public
forums, where I and others can see and answer them.

--~--~---------~--~----~------------~-------~--~----~

2. FloatBuffer.put() bug...

There seems to be a bug where calling FloatBuffer.put() on a buffer
create as such :

ByteBuffer bufferVerts = ByteBuffer.allocateDirect(numVerts * 3 * 4);
bufferVerts.order(ByteOrder.nativeOrder());
m_bufferVerts = bufferVerts.asFloatBuffer();
m_bufferVerts.position(0);

does not properly write. Basically, calling :

m_bufferVerts.put(-0.5f);
m_bufferVerts.put(0.5f);
m_bufferVerts.put(0.0f);

does not give a vert at that location. The vert location is random
(Changes each time I run the app), indicating that put did not write
anything, leaving memory to whatever garbage it initially had.

However, calling

m_bufferVerts.put(0, -0.5f);
m_bufferVerts.put(1, 0.5f);
m_bufferVerts.put(2, 0.0f);

works.

I can keep my own position counter, but since FloatBuffer claims to
have one internally, shouldn't those two pieces of code have the same
result?

--~--~---------~--~----~------------~-------~--~----~

3. PV Open Core architecture docs

4. Regarding 3gp2 parser and EVRC decoder

5. Name that service ...

6. embedded platform

7. Authentication using login / password with Android.