Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving to the next EditText in android

Tags:

android

According to the question and answer posted How to automatically move to the next edit text in android , I used the code to move to the next edit box.

et1.addTextChangedListener(new TextWatcher() {      public void onTextChanged(CharSequence s, int start,int before, int count)      {         // TODO Auto-generated method stub         if(et1.getText().toString().length()==size)     //size as per your requirement         {             et2.requestFocus();         }     }     public void beforeTextChanged(CharSequence s, int start,                     int count, int after) {                 // TODO Auto-generated method stub      }      public void afterTextChanged(Editable s) {                 // TODO Auto-generated method stub     }  }); 

The issue I am facing is in case I enter something wrong, then even if the user explicitly request focus , the text box moves to the next one due to the code in the text watcher. Is there anything I can do to prevent this from happening ?

like image 501
user1667307 Avatar asked Sep 19 '12 04:09

user1667307


People also ask

How to jump to next EditText in android?

According to the question and answer posted How to automatically move to the next edit text in android , I used the code to move to the next edit box. et1. addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start,int before, int count) { // TODO Auto-generated method stub if(et1.

How do I change the focus to next text in Android?

Use android:nextFocusDown="next_EditText_id" Show activity on this post. Show activity on this post. The solution coding is OK, Below codes indicate that auto move to next Edit Text and auto move to previous Edit Text.

How do I change from focus to EditText?

This solution works (no need to add android:focusable="true"\android:focusableInTouchMode="true"): final EditText userEditText = (EditText)findViewById(R. id.

What is Imeoption Android?

android:imeOptions="actionSend" /> You can then listen for presses on the action button by defining a TextView.OnEditorActionListener for the EditText element. In your listener, respond to the appropriate IME action ID defined in the EditorInfo class, such as IME_ACTION_SEND . For example: Kotlin Java.


2 Answers

It might be very late but I have a solution which is much easier to apply. Just add this code to the edittext field in the layout.xml file. Add this to edittext which you want to show a next button instead of a done button. So it will point to the next Edittext field.

android:imeOptions="actionNext" 
like image 154
arshu Avatar answered Sep 30 '22 14:09

arshu


If you want to focus next EditText on enter pressed you can use those options at XML code to focus next EditText:

Option 1:

<EditText     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:imeOptions="actionNext"     android:singleLine="true"/> 

Option 2:

<EditText     android:id="@+id/et1"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:singleLine="true"     android:nextFocusForward="@+id/et2"/>  <EditText     android:id="@+id/et2"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:singleLine="true"/> 
like image 28
Daniel López Avatar answered Sep 30 '22 13:09

Daniel López