The User can enter only one digit in the edit text. if he enters the value in edtText1, I want the cursor automatically moves to edtText2 and so on. The user can able to edit the text which he/she has entered already. I tried the following way.
edtPasscode1.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (edtPasscode1.getText().length() == 1)
edtPasscode2.requestFocus();
return false;
}
});
edtPasscode2.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (edtPasscode2.getText().length() == 1)
edtPasscode3.requestFocus();
return false;
}
});
edtPasscode3.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (edtPasscode3.getText().length() == 1)
edtPasscode4.requestFocus();
return false;
}
});
If the user edit the text, The cursor moves to some other editTexts and not working as desired. How can i achieve the above?
set
android:maxLength="1"
to all yourExitText
in xmlTry the following code
This should work
The solution coding is OK,
Below codes indicate that auto move to next Edit Text and auto move to previous Edit Text.
It also OK if you are using Rxjava + Data Binding + RxBinding in below :
set the length to editetxt as
android:maxLength="1"
and follow the below codeYou can use use a hidden EditText receive input, four TextView to display the password.
example:
dialog_passworld.xml
PasswordDialogBuilder.java
This worked for my case, also max_length of edit text should be 1.
Try TextWatcher instead of onKeyListener
B'coz if want to edit your password, in that case TextWatcher will give you more method to dealt with..
Edited:-
Hope this work.