8

我想将光标从 EditText1 移动到另一个 EditText2 。我已经专注于editText1,但是如何将光标移动到editText2。?

4

5 回答 5

13

最后我得到了答案:

 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

                }
            });
于 2012-09-14T06:16:47.730 回答
3

我能理解你的回答,

但是还有另一种好方法,只需使用以下属性

android:imeOptions="actionNext"

这个例子 :

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

谢谢,

于 2013-12-02T03:23:45.303 回答
0

在您的edittext1单击代码中设置属性...

EditText2.requestFocus();

于 2012-09-14T05:33:00.683 回答
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;
}
});
于 2012-09-14T05:53:57.303 回答
0
android:inputType="textEmailAddress"//Add this line
于 2022-02-04T11:59:38.413 回答