from 1st edittext going to 2nd edittext, input mask not working












0















I have 6 edittexts (will be using for OTP)

Each edittext will only allow 1 character and then transfer to another edittext



Here is the sample code:



et1.requestFocus()

et1.addTextChangedListener(new TextWatcher() {

public void onTextChanged(CharSequence s, int start,int before, int count {
if(et1.getText().toString().length()==size){
et2.requestFocus();
}
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {}

public void afterTextChanged(Editable s) {
et1.setTransformationMethod(new PasswordTransformationMethod());
}

});


What happens is, the et1, doesn't mask itself as dot/asterisk but the focus is transferred to et2.

But whenever I tap it again, it masks itself.



Edit: Already added inputType="numberPassword" in my XML but still not working










share|improve this question

























  • Why u dont settext as password in ur XML?

    – Catluc
    Nov 22 '18 at 14:59













  • already did. InputType="numberPassword"

    – MaChee Neraid
    Nov 22 '18 at 15:01











  • and android:inputType="textPassword"?

    – Catluc
    Nov 22 '18 at 15:03











  • It looks like a duplicate question : stackoverflow.com/questions/12470067/…

    – Catluc
    Nov 22 '18 at 15:09











  • no its not. in my situation. I need the mask. the request focus is already working

    – MaChee Neraid
    Nov 22 '18 at 15:11
















0















I have 6 edittexts (will be using for OTP)

Each edittext will only allow 1 character and then transfer to another edittext



Here is the sample code:



et1.requestFocus()

et1.addTextChangedListener(new TextWatcher() {

public void onTextChanged(CharSequence s, int start,int before, int count {
if(et1.getText().toString().length()==size){
et2.requestFocus();
}
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {}

public void afterTextChanged(Editable s) {
et1.setTransformationMethod(new PasswordTransformationMethod());
}

});


What happens is, the et1, doesn't mask itself as dot/asterisk but the focus is transferred to et2.

But whenever I tap it again, it masks itself.



Edit: Already added inputType="numberPassword" in my XML but still not working










share|improve this question

























  • Why u dont settext as password in ur XML?

    – Catluc
    Nov 22 '18 at 14:59













  • already did. InputType="numberPassword"

    – MaChee Neraid
    Nov 22 '18 at 15:01











  • and android:inputType="textPassword"?

    – Catluc
    Nov 22 '18 at 15:03











  • It looks like a duplicate question : stackoverflow.com/questions/12470067/…

    – Catluc
    Nov 22 '18 at 15:09











  • no its not. in my situation. I need the mask. the request focus is already working

    – MaChee Neraid
    Nov 22 '18 at 15:11














0












0








0








I have 6 edittexts (will be using for OTP)

Each edittext will only allow 1 character and then transfer to another edittext



Here is the sample code:



et1.requestFocus()

et1.addTextChangedListener(new TextWatcher() {

public void onTextChanged(CharSequence s, int start,int before, int count {
if(et1.getText().toString().length()==size){
et2.requestFocus();
}
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {}

public void afterTextChanged(Editable s) {
et1.setTransformationMethod(new PasswordTransformationMethod());
}

});


What happens is, the et1, doesn't mask itself as dot/asterisk but the focus is transferred to et2.

But whenever I tap it again, it masks itself.



Edit: Already added inputType="numberPassword" in my XML but still not working










share|improve this question
















I have 6 edittexts (will be using for OTP)

Each edittext will only allow 1 character and then transfer to another edittext



Here is the sample code:



et1.requestFocus()

et1.addTextChangedListener(new TextWatcher() {

public void onTextChanged(CharSequence s, int start,int before, int count {
if(et1.getText().toString().length()==size){
et2.requestFocus();
}
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {}

public void afterTextChanged(Editable s) {
et1.setTransformationMethod(new PasswordTransformationMethod());
}

});


What happens is, the et1, doesn't mask itself as dot/asterisk but the focus is transferred to et2.

But whenever I tap it again, it masks itself.



Edit: Already added inputType="numberPassword" in my XML but still not working







android android-edittext onfocus






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 15:47







MaChee Neraid

















asked Nov 22 '18 at 14:56









MaChee NeraidMaChee Neraid

518




518













  • Why u dont settext as password in ur XML?

    – Catluc
    Nov 22 '18 at 14:59













  • already did. InputType="numberPassword"

    – MaChee Neraid
    Nov 22 '18 at 15:01











  • and android:inputType="textPassword"?

    – Catluc
    Nov 22 '18 at 15:03











  • It looks like a duplicate question : stackoverflow.com/questions/12470067/…

    – Catluc
    Nov 22 '18 at 15:09











  • no its not. in my situation. I need the mask. the request focus is already working

    – MaChee Neraid
    Nov 22 '18 at 15:11



















  • Why u dont settext as password in ur XML?

    – Catluc
    Nov 22 '18 at 14:59













  • already did. InputType="numberPassword"

    – MaChee Neraid
    Nov 22 '18 at 15:01











  • and android:inputType="textPassword"?

    – Catluc
    Nov 22 '18 at 15:03











  • It looks like a duplicate question : stackoverflow.com/questions/12470067/…

    – Catluc
    Nov 22 '18 at 15:09











  • no its not. in my situation. I need the mask. the request focus is already working

    – MaChee Neraid
    Nov 22 '18 at 15:11

















Why u dont settext as password in ur XML?

– Catluc
Nov 22 '18 at 14:59







Why u dont settext as password in ur XML?

– Catluc
Nov 22 '18 at 14:59















already did. InputType="numberPassword"

– MaChee Neraid
Nov 22 '18 at 15:01





already did. InputType="numberPassword"

– MaChee Neraid
Nov 22 '18 at 15:01













and android:inputType="textPassword"?

– Catluc
Nov 22 '18 at 15:03





and android:inputType="textPassword"?

– Catluc
Nov 22 '18 at 15:03













It looks like a duplicate question : stackoverflow.com/questions/12470067/…

– Catluc
Nov 22 '18 at 15:09





It looks like a duplicate question : stackoverflow.com/questions/12470067/…

– Catluc
Nov 22 '18 at 15:09













no its not. in my situation. I need the mask. the request focus is already working

– MaChee Neraid
Nov 22 '18 at 15:11





no its not. in my situation. I need the mask. the request focus is already working

– MaChee Neraid
Nov 22 '18 at 15:11












1 Answer
1






active

oldest

votes


















1














try this way




xml




<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">

<EditText
android:id="@+id/otp_first_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />

<EditText
android:id="@+id/otp_second_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />

<EditText
android:id="@+id/otp_third_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />

<EditText
android:id="@+id/otp_fourth_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:imeOptions="actionDone"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />
</LinearLayout>



java




EditText otpEditTextFirst, otpEditTextSecond, otpEditTextThird, otpEditTextFourth;

otpEditTextFirst = (EditText) findViewById(R.id.otp_first_et);
otpEditTextSecond = (EditText) findViewById(R.id.otp_second_et);
otpEditTextThird = (EditText) findViewById(R.id.otp_third_et);
otpEditTextFourth = (EditText) findViewById(R.id.otp_fourth_et);


otpEditTextFirst.addTextChangedListener(new GenericTextWatcher(otpEditTextFirst));
otpEditTextSecond.addTextChangedListener(new GenericTextWatcher(otpEditTextSecond));
otpEditTextThird.addTextChangedListener(new GenericTextWatcher(otpEditTextThird));
otpEditTextFourth.addTextChangedListener(new GenericTextWatcher(otpEditTextFourth));


class GenericTextWatcher implements TextWatcher {
private View view;

private GenericTextWatcher(View view) {
this.view = view;
}

@Override
public void afterTextChanged(Editable editable) {
// TODO Auto-generated method stub
String text = editable.toString();
switch (view.getId()) {

case R.id.otp_first_et:

if (text.length() == 1)
otpEditTextSecond.requestFocus();


break;
case R.id.otp_second_et:

if (text.length() == 1)
otpEditTextThird.requestFocus();

else
otpEditTextFirst.requestFocus();
break;
case R.id.otp_third_et:

if (text.length() == 1)
otpEditTextFourth.requestFocus();

else
otpEditTextSecond.requestFocus();
break;
case R.id.otp_fourth_et:
if (text.length() == 0)
otpEditTextThird.requestFocus();


break;
}
}

@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}

@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
}





share|improve this answer
























  • wow indeed this is what I needed! I just edited the inputType into numberPassword! wow! thanks bro! you have my up!

    – MaChee Neraid
    Nov 22 '18 at 16:39











  • do you mind sharing why my code doesn't work? after analyzing, it does the same thing like yours.

    – MaChee Neraid
    Nov 22 '18 at 16:46











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433591%2ffrom-1st-edittext-going-to-2nd-edittext-input-mask-not-working%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














try this way




xml




<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">

<EditText
android:id="@+id/otp_first_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />

<EditText
android:id="@+id/otp_second_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />

<EditText
android:id="@+id/otp_third_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />

<EditText
android:id="@+id/otp_fourth_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:imeOptions="actionDone"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />
</LinearLayout>



java




EditText otpEditTextFirst, otpEditTextSecond, otpEditTextThird, otpEditTextFourth;

otpEditTextFirst = (EditText) findViewById(R.id.otp_first_et);
otpEditTextSecond = (EditText) findViewById(R.id.otp_second_et);
otpEditTextThird = (EditText) findViewById(R.id.otp_third_et);
otpEditTextFourth = (EditText) findViewById(R.id.otp_fourth_et);


otpEditTextFirst.addTextChangedListener(new GenericTextWatcher(otpEditTextFirst));
otpEditTextSecond.addTextChangedListener(new GenericTextWatcher(otpEditTextSecond));
otpEditTextThird.addTextChangedListener(new GenericTextWatcher(otpEditTextThird));
otpEditTextFourth.addTextChangedListener(new GenericTextWatcher(otpEditTextFourth));


class GenericTextWatcher implements TextWatcher {
private View view;

private GenericTextWatcher(View view) {
this.view = view;
}

@Override
public void afterTextChanged(Editable editable) {
// TODO Auto-generated method stub
String text = editable.toString();
switch (view.getId()) {

case R.id.otp_first_et:

if (text.length() == 1)
otpEditTextSecond.requestFocus();


break;
case R.id.otp_second_et:

if (text.length() == 1)
otpEditTextThird.requestFocus();

else
otpEditTextFirst.requestFocus();
break;
case R.id.otp_third_et:

if (text.length() == 1)
otpEditTextFourth.requestFocus();

else
otpEditTextSecond.requestFocus();
break;
case R.id.otp_fourth_et:
if (text.length() == 0)
otpEditTextThird.requestFocus();


break;
}
}

@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}

@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
}





share|improve this answer
























  • wow indeed this is what I needed! I just edited the inputType into numberPassword! wow! thanks bro! you have my up!

    – MaChee Neraid
    Nov 22 '18 at 16:39











  • do you mind sharing why my code doesn't work? after analyzing, it does the same thing like yours.

    – MaChee Neraid
    Nov 22 '18 at 16:46
















1














try this way




xml




<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">

<EditText
android:id="@+id/otp_first_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />

<EditText
android:id="@+id/otp_second_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />

<EditText
android:id="@+id/otp_third_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />

<EditText
android:id="@+id/otp_fourth_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:imeOptions="actionDone"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />
</LinearLayout>



java




EditText otpEditTextFirst, otpEditTextSecond, otpEditTextThird, otpEditTextFourth;

otpEditTextFirst = (EditText) findViewById(R.id.otp_first_et);
otpEditTextSecond = (EditText) findViewById(R.id.otp_second_et);
otpEditTextThird = (EditText) findViewById(R.id.otp_third_et);
otpEditTextFourth = (EditText) findViewById(R.id.otp_fourth_et);


otpEditTextFirst.addTextChangedListener(new GenericTextWatcher(otpEditTextFirst));
otpEditTextSecond.addTextChangedListener(new GenericTextWatcher(otpEditTextSecond));
otpEditTextThird.addTextChangedListener(new GenericTextWatcher(otpEditTextThird));
otpEditTextFourth.addTextChangedListener(new GenericTextWatcher(otpEditTextFourth));


class GenericTextWatcher implements TextWatcher {
private View view;

private GenericTextWatcher(View view) {
this.view = view;
}

@Override
public void afterTextChanged(Editable editable) {
// TODO Auto-generated method stub
String text = editable.toString();
switch (view.getId()) {

case R.id.otp_first_et:

if (text.length() == 1)
otpEditTextSecond.requestFocus();


break;
case R.id.otp_second_et:

if (text.length() == 1)
otpEditTextThird.requestFocus();

else
otpEditTextFirst.requestFocus();
break;
case R.id.otp_third_et:

if (text.length() == 1)
otpEditTextFourth.requestFocus();

else
otpEditTextSecond.requestFocus();
break;
case R.id.otp_fourth_et:
if (text.length() == 0)
otpEditTextThird.requestFocus();


break;
}
}

@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}

@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
}





share|improve this answer
























  • wow indeed this is what I needed! I just edited the inputType into numberPassword! wow! thanks bro! you have my up!

    – MaChee Neraid
    Nov 22 '18 at 16:39











  • do you mind sharing why my code doesn't work? after analyzing, it does the same thing like yours.

    – MaChee Neraid
    Nov 22 '18 at 16:46














1












1








1







try this way




xml




<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">

<EditText
android:id="@+id/otp_first_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />

<EditText
android:id="@+id/otp_second_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />

<EditText
android:id="@+id/otp_third_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />

<EditText
android:id="@+id/otp_fourth_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:imeOptions="actionDone"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />
</LinearLayout>



java




EditText otpEditTextFirst, otpEditTextSecond, otpEditTextThird, otpEditTextFourth;

otpEditTextFirst = (EditText) findViewById(R.id.otp_first_et);
otpEditTextSecond = (EditText) findViewById(R.id.otp_second_et);
otpEditTextThird = (EditText) findViewById(R.id.otp_third_et);
otpEditTextFourth = (EditText) findViewById(R.id.otp_fourth_et);


otpEditTextFirst.addTextChangedListener(new GenericTextWatcher(otpEditTextFirst));
otpEditTextSecond.addTextChangedListener(new GenericTextWatcher(otpEditTextSecond));
otpEditTextThird.addTextChangedListener(new GenericTextWatcher(otpEditTextThird));
otpEditTextFourth.addTextChangedListener(new GenericTextWatcher(otpEditTextFourth));


class GenericTextWatcher implements TextWatcher {
private View view;

private GenericTextWatcher(View view) {
this.view = view;
}

@Override
public void afterTextChanged(Editable editable) {
// TODO Auto-generated method stub
String text = editable.toString();
switch (view.getId()) {

case R.id.otp_first_et:

if (text.length() == 1)
otpEditTextSecond.requestFocus();


break;
case R.id.otp_second_et:

if (text.length() == 1)
otpEditTextThird.requestFocus();

else
otpEditTextFirst.requestFocus();
break;
case R.id.otp_third_et:

if (text.length() == 1)
otpEditTextFourth.requestFocus();

else
otpEditTextSecond.requestFocus();
break;
case R.id.otp_fourth_et:
if (text.length() == 0)
otpEditTextThird.requestFocus();


break;
}
}

@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}

@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
}





share|improve this answer













try this way




xml




<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">

<EditText
android:id="@+id/otp_first_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />

<EditText
android:id="@+id/otp_second_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />

<EditText
android:id="@+id/otp_third_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />

<EditText
android:id="@+id/otp_fourth_et"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginBottom="10dp"
android:digits="0123456789"
android:drawablePadding="7dp"
android:gravity="center"
android:imeOptions="actionDone"
android:inputType="number"
android:maxLength="1"
android:paddingLeft="10dp"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textCursorDrawable="@drawable/bg_edit_text_cursor" />
</LinearLayout>



java




EditText otpEditTextFirst, otpEditTextSecond, otpEditTextThird, otpEditTextFourth;

otpEditTextFirst = (EditText) findViewById(R.id.otp_first_et);
otpEditTextSecond = (EditText) findViewById(R.id.otp_second_et);
otpEditTextThird = (EditText) findViewById(R.id.otp_third_et);
otpEditTextFourth = (EditText) findViewById(R.id.otp_fourth_et);


otpEditTextFirst.addTextChangedListener(new GenericTextWatcher(otpEditTextFirst));
otpEditTextSecond.addTextChangedListener(new GenericTextWatcher(otpEditTextSecond));
otpEditTextThird.addTextChangedListener(new GenericTextWatcher(otpEditTextThird));
otpEditTextFourth.addTextChangedListener(new GenericTextWatcher(otpEditTextFourth));


class GenericTextWatcher implements TextWatcher {
private View view;

private GenericTextWatcher(View view) {
this.view = view;
}

@Override
public void afterTextChanged(Editable editable) {
// TODO Auto-generated method stub
String text = editable.toString();
switch (view.getId()) {

case R.id.otp_first_et:

if (text.length() == 1)
otpEditTextSecond.requestFocus();


break;
case R.id.otp_second_et:

if (text.length() == 1)
otpEditTextThird.requestFocus();

else
otpEditTextFirst.requestFocus();
break;
case R.id.otp_third_et:

if (text.length() == 1)
otpEditTextFourth.requestFocus();

else
otpEditTextSecond.requestFocus();
break;
case R.id.otp_fourth_et:
if (text.length() == 0)
otpEditTextThird.requestFocus();


break;
}
}

@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}

@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 15:12









Aniruddh PariharAniruddh Parihar

2,17911027




2,17911027













  • wow indeed this is what I needed! I just edited the inputType into numberPassword! wow! thanks bro! you have my up!

    – MaChee Neraid
    Nov 22 '18 at 16:39











  • do you mind sharing why my code doesn't work? after analyzing, it does the same thing like yours.

    – MaChee Neraid
    Nov 22 '18 at 16:46



















  • wow indeed this is what I needed! I just edited the inputType into numberPassword! wow! thanks bro! you have my up!

    – MaChee Neraid
    Nov 22 '18 at 16:39











  • do you mind sharing why my code doesn't work? after analyzing, it does the same thing like yours.

    – MaChee Neraid
    Nov 22 '18 at 16:46

















wow indeed this is what I needed! I just edited the inputType into numberPassword! wow! thanks bro! you have my up!

– MaChee Neraid
Nov 22 '18 at 16:39





wow indeed this is what I needed! I just edited the inputType into numberPassword! wow! thanks bro! you have my up!

– MaChee Neraid
Nov 22 '18 at 16:39













do you mind sharing why my code doesn't work? after analyzing, it does the same thing like yours.

– MaChee Neraid
Nov 22 '18 at 16:46





do you mind sharing why my code doesn't work? after analyzing, it does the same thing like yours.

– MaChee Neraid
Nov 22 '18 at 16:46


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433591%2ffrom-1st-edittext-going-to-2nd-edittext-input-mask-not-working%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Create new schema in PostgreSQL using DBeaver

Deepest pit of an array with Javascript: test on Codility

Costa Masnaga