-1

Currently developing a keyboard. Whenever I press an EditText, the typing cursor moves to the end of all the words in the EditText automatically. It won't let me start editing within the middle of a sentence.

Scenerio:

User presses an EditText and my keyboard pops up. User types "Banana". User backs out of keyboard (keyboard closes). User presses on edittext with the word "Banana" in it and presses on the middle N. The cursor shows up after the N for half a second and then automatically moves to the end of the word.

Basically what I'm looking for is how to stop an IME from doing this automatically.

Faris
  • 81
  • 1
  • 6
  • Sorry, it's a bit late, my mind-reading skills are a bit weary. Can you show your pertinent code? It'll probably help us help you. – Cat Aug 04 '12 at 05:56

1 Answers1

1

Use setSelection(int no) with OnFocusChangeListener() of EditText in following way:

et1.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(v.hasFocus()) {
                    int len = et1.getEditableText().toString().trim().length();
                    if(len > 1)
                        et1.setSelection((int)len/2);
                }
            }
        });
Chintan Raghwani
  • 3,370
  • 4
  • 22
  • 33
  • The problem is I don't have a handle to "et1" since it is basically any EditText in any app. I do, however, have a handle to the EditorInfo object of any EditText I click with @Override public void onStartInputView (EditorInfo attribute, boolean restarting) { } – Faris Aug 04 '12 at 06:16