Android Moving the cursor from one EditText to another, if you press any letter in the field?

I want to move the cursor from EditText1 to another EditText2. I have already focused on editText1, but how to move the cursor to editText2.?

+6
source share
4 answers

Finally, 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 } }); 
+10
source

I can understand your answer

But there is another good way to do this, simply using the following attribute

Android: imeOptions = "actionNext"

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,

+2
source

Set properties in click code edittext1 ...

EditText2.requestFocus ();

0
source
  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; } }); 
0
source

Source: https://habr.com/ru/post/925381/


All Articles