Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Move cursor from one EditText to another one if click any letter in field?

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

like image 486
anoop Avatar asked Sep 14 '12 04:09

anoop


People also ask

How do I move cursor from one editText to another in Android?

Say in your xml's edittext section, add android:paddingLeft="100dp" This will move your start position of cursor 100dp right from left end. Same way, you can use android:paddingRight="100dp" This will move your end position of cursor 100dp left from right end.


2 Answers

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

                }
            });
like image 88
anoop Avatar answered Sep 20 '22 19:09

anoop


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,

like image 40
Huy Tower Avatar answered Sep 18 '22 19:09

Huy Tower