Android Move cursor from one EditText to another one?

full Error picture full Error · May 1, 2012 · Viewed 16.8k times · Source

I know these type of question asked many time .but still nobody gave perfect answer for that.

I have question :

I want to move from EditText1 ** to another **EditText2 . I had already detect to editText1 but how to move cursor to editText2.?

In short I had to move my cursor position from one editText1 to another EditText2 directly.

Answer

NovusMobile picture NovusMobile · May 2, 2012

I faced this type of issue and found the solution as below.

Here I have two editText ,

if I press "a", my cursor will move to next step . I used below code for doing it.

 final EditText editText = (EditText) findViewById(R.id.editText1);

       editText.setOnKeyListener(new OnKeyListener() {

            @Override
            public boolean onKey(View v , int keyCode , KeyEvent event) {

                  EditText editText2 = (EditText) findViewById(R.id.editText2);

                // TODO Auto-generated method stub
                if (keyCode == event.KEYCODE_A) {

                    Selection.setSelection((Editable) editText2.getText(),editText.getSelectionStart());
                    editText2.requestFocus();
                }

                return true;
            }
        });

let me know if you are facing any error regarding this. If my answer is helpful to you please accept it and rate to upvote.