Android Move cursor from one EditText to another o

2019-04-23 10:52发布

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

4条回答
Lonely孤独者°
2楼-- · 2019-04-23 11:12

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,

查看更多
叼着烟拽天下
3楼-- · 2019-04-23 11:17

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

                }
            });
查看更多
女痞
4楼-- · 2019-04-23 11:25

Set properties in your edittext1 click code...

EditText2.requestFocus();

查看更多
贼婆χ
5楼-- · 2019-04-23 11:28
  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;
}
});
查看更多
登录 后发表回答