8

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

Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128
anoop
  • 782
  • 4
  • 12
  • 35
  • maybe add a [TextWatcher](http://developer.android.com/reference/android/text/TextWatcher.html) on your `EditText1` – Aprian Sep 14 '12 at 04:54
  • see my answer here:http://stackoverflow.com/questions/9003166/android-keyboard-next-button-issue-on-edittext/9003285#9003285 It might help. – Hiral Vadodaria Sep 14 '12 at 05:00
  • Thank both of u (Aprian and Hiral) for ur help. Now its working, TextWatcher help me ..... – anoop Sep 14 '12 at 05:39

5 Answers5

13

Finaly i got the answer:

 editText1.addTextChangedListener(new TextWatcher() {

                public void onTextChanged(CharSequence s, int start, int before,
                        int count) {
                    Integer textlength1 = editText1.getText().length();

                    if (textlength1 >= 1) { 
                        editText2.requestFocus();
                    }
                }

                @Override
                public void afterTextChanged(Editable s) {
                    // TODO Auto-generated method stub
                }

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count,
                        int after) {
                    // TODO Auto-generated method stub
                }
            });

            editText2.addTextChangedListener(new TextWatcher() {

                public void onTextChanged(CharSequence s, int start, int before,
                        int count) {
                    Integer textlength2 = editText1.getText().length();

                    if (textlength2 >= 1) {
                        editText3.requestFocus();

                    }
                }

                @Override
                public void afterTextChanged(Editable s) {
                    // TODO Auto-generated method stub
                }

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count,
                        int after) {
                    // TODO Auto-generated method stub

                }
            });
anoop
  • 782
  • 4
  • 12
  • 35
4

I can understand your answer,

But there is another good way to do it simply by using the following attribute

android:imeOptions="actionNext"

The example :

<EditText
android:hint="@string/hint_user_name"
android:id="@+id/et_user_name"
android:maxLines="2"
style="@style/EditText_Login"
android:imeOptions="actionNext" 
/>

Thanks,

Huy Tower
  • 7,769
  • 16
  • 61
  • 86
0

Set properties in your edittext1 click code...

EditText2.requestFocus();

SBJ
  • 4,089
  • 3
  • 24
  • 27
0
  EditText editText1 = (EditText)findViewById(R.id.editText1 );
  EditText editText2 = (EditText)findViewById(R.id.editText2);


editText1.setOnKeyListener(new OnKeyListener() {

public boolean onKey(View v, int keyCode, KeyEvent event) {
      // If the event is a key-down event on the "enter" button
      if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
           (keyCode == KeyEvent.KEYCODE_ENTER))
      {
            // Perform action on Enter key press
            editText1.clearFocus();
            editText2.requestFocus();
            return true;
      }
      return false;
}
});
Vins
  • 4,089
  • 2
  • 35
  • 50
0
android:inputType="textEmailAddress"//Add this line
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
  • 1
    Your answer could be improved by adding more information on what the code does and how it helps the OP. – Tyler2P Feb 13 '22 at 16:35