mukeshsolanki / android-otpview-pinview

A custom view to enter otp of different sizes used usually in cases of authentication.
MIT License
714 stars 206 forks source link

setOTP exception #8

Closed pittgikera closed 6 years ago

pittgikera commented 7 years ago

Calling setOTP on the otpView produces an exception.

E/AndroidRuntime: FATAL EXCEPTION: main

                                                                      android.content.res.Resources$NotFoundException: String resource ID #0x30
                                                                          at android.content.res.Resources.getText(Resources.java:354)
                                                                          at android.widget.TextView.setText(TextView.java:4167)
                                                                          at com.mukesh.OtpView.setOTP(OtpView.java:95)
                                                                          at android.support.v4.app.Fragment.performCreateView(Fragment.java:2343)
                                                                          at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
                                                                          at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
                                                                          at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
                                                                          at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799)
                                                                          at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580)
                                                                          at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367)
                                                                          at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322)
                                                                          at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229)
                                                                          at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:700)
                                                                          at android.os.Handler.handleCallback(Handler.java:815)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:104)
                                                                          at android.os.Looper.loop(Looper.java:194)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5637)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at java.lang.reflect.Method.invoke(Method.java:372)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
riyal123 commented 7 years ago

any update on this?

Virendra-Varma commented 6 years ago

add an additional if for checking the next or previous focus available or not in afterTextChanged like this

@Override public void afterTextChanged(Editable s) { if (mCurrentlyFocusedEditText.focusSearch(FOCUS_RIGHT) != null || mCurrentlyFocusedEditText.focusSearch(FOCUS_LEFT) != null) { if (mCurrentlyFocusedEditText.getText().length() >= 1 && mCurrentlyFocusedEditText != mOtpFourField) { mCurrentlyFocusedEditText.focusSearch(View.FOCUS_RIGHT).requestFocus(); } else if (mCurrentlyFocusedEditText.getText().length() >= 1 && mCurrentlyFocusedEditText == mOtpFourField) { InputMethodManager imm = (InputMethodManager) getContext().getSystemService( Context.INPUT_METHOD_SERVICE); if (imm != null) { imm.hideSoftInputFromWindow(getWindowToken(), 0); } } else { String currentValue = mCurrentlyFocusedEditText.getText().toString(); if (currentValue.length() <= 0 && mCurrentlyFocusedEditText.getSelectionStart() <= 0) { mCurrentlyFocusedEditText.focusSearch(View.FOCUS_LEFT).requestFocus(); } } } }

mukeshsolanki commented 6 years ago

The issue is with you setting number as a string please convert the value to a string data type and check