-1

I have two textViews shown below after pressing enter button in first textview the cursor should goes to second textview. How?

    <AutoCompleteTextView
        android:id="@+id/txt_login_username"
        android:layout_width="300dp"
        android:layout_height="40dp"
        android:layout_above="@+id/pengala_logo"
        android:layout_alignLeft="@+id/txt_login_pwd"
        android:ems="10"
        android:hint="Please enter Email"
        android:inputType="textAutoComplete"
        android:textColorHint="#ffffff"
        android:textSize="20sp" />

    <requestFocus />

    <EditText
        android:id="@+id/txt_login_pwd"
        android:layout_width="300dp"
        android:layout_height="40dp"
        android:layout_alignLeft="@+id/btn_login_submit"
        android:layout_alignTop="@+id/text"
        android:ems="10"
        android:hint="Please enter Password"
        android:inputType="textPassword"
        android:textColorHint="#ffffff"
        android:textSize="20sp" />
Cœur
  • 34,719
  • 24
  • 185
  • 251
Dev
  • 98
  • 1
  • 11

4 Answers4

2

try this, EditBox have the requestFocus() you can use this while clicking Button.

EditText.requestFocus();
Murali Ganesan
  • 2,815
  • 4
  • 18
  • 29
1

Looking at this question, you can simply use the android:imeOptions="actionNext" option on your txt_login_username to change the 'enter' key to go to the 'next' input. You may need to specify android:singleLine="true", as this will not work on a multi-line input.

Documentation can be found here.

Community
  • 1
  • 1
CodeMonkey
  • 1,366
  • 1
  • 12
  • 31
  • This is more generic. The other answers provide little scope for scaling. Thanx – Anudeep Bulla Sep 24 '13 at 06:56
  • This works in with how Android forms are designed, rather than listening for keypresses in the background. Android will even replace `Next` with `Go` on the enter button once you reach then end of your form. – CodeMonkey Sep 24 '13 at 07:01
1

I think it should work

EditText editText1=(EditText)findViewById(R.id.text1);
EditText editTtext2=(EditText)findViewById(R.id.text2);
        editText1.setOnKeyListener(new OnKeyListener() {

            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if(event.getKeyCode() == KeyEvent.KEYCODE_ENTER){
                    editTtext2.requestFocus();
                }
                return true;
            }
        });

Make editText1 single line true.

Mukesh Kumar Singh
  • 4,478
  • 2
  • 21
  • 30
0
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;
            }
        });
Robi Kumar Tomar
  • 3,420
  • 3
  • 18
  • 27