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 ?
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.
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.
This solution works (no need to add android:focusable="true"\android:focusableInTouchMode="true"): final EditText userEditText = (EditText)findViewById(R. id.
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.
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"
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"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With