CountryCodePickerProject
CountryCodePickerProject copied to clipboard
Auto-Formatting not working: java.lang.IndexOutOfBoundsException: setSpan (5 ... 5) ends beyond length 4
java.lang.IndexOutOfBoundsException: setSpan (5 ... 5) ends beyond length 4
at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1265)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:684)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:677)
at android.text.Selection.setSelection(Selection.java:76)
at android.text.Selection.setSelection(Selection.java:87)
at com.hbb20.InternationalPhoneTextWatcher.afterTextChanged(InternationalPhoneTextWatcher.java:168)
at android.widget.TextView.sendAfterTextChanged(TextView.java:9443)
at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:12348)
at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:1218)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:579)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:509)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:508)
at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:850)
at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:200)
at com.android.internal.widget.EditableInputConnection.commitText(EditableInputConnection.java:183)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:345)
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:91)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
implementation 'com.hbb20:ccp:2.3.7'
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_8sdp"
android:gravity="center_vertical">
<com.hbb20.CountryCodePicker
android:id="@+id/ccp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:ccp_autoFormatNumber="true"
app:ccp_contentColor="@color/white"
app:ccp_defaultLanguage="ENGLISH"
app:ccp_defaultNameCode="US"
app:ccp_showFullName="false"
app:ccp_showNameCode="false"
app:ccp_showPhoneCode="true" />
<com.coomotravel.app.utils.customviews.CustomEditText
android:id="@+id/et_phone_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:digits="0123456789"
android:ellipsize="end"
android:imeOptions="actionDone"
android:inputType="phone"
android:paddingEnd="@dimen/_8sdp"
android:textColor="@color/white"
android:textSize="@dimen/_15ssp"
android:theme="@style/EditTextBackgroundTint"
app:customFont="Avenir-Medium.ttf" />
</LinearLayout>
and in onCreate()
method ccp.registerCarrierNumberEditText(etPhoneNumber);
Try by removing android:digits="0123456789" because auto formatting needs to add other characters. Please post back if that works for you.
On Thu, Feb 6, 2020 at 23:40 malik082009 [email protected] wrote:
java.lang.IndexOutOfBoundsException: setSpan (5 ... 5) ends beyond length 4 at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1265) at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:684) at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:677) at android.text.Selection.setSelection(Selection.java:76) at android.text.Selection.setSelection(Selection.java:87) at com.hbb20.InternationalPhoneTextWatcher.afterTextChanged(InternationalPhoneTextWatcher.java:168) at android.widget.TextView.sendAfterTextChanged(TextView.java:9443) at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:12348) at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:1218) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:579) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:509) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:508) at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:850) at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:200) at com.android.internal.widget.EditableInputConnection.commitText(EditableInputConnection.java:183) at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:345) at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:91) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6682) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
implementation 'com.hbb20:ccp:2.3.7'
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/_8sdp" android:gravity="center_vertical"> <com.hbb20.CountryCodePicker android:id="@+id/ccp" android:layout_width="wrap_content" android:layout_height="wrap_content" app:ccp_autoFormatNumber="true" app:ccp_contentColor="@color/white" app:ccp_defaultLanguage="ENGLISH" app:ccp_defaultNameCode="US" app:ccp_showFullName="false" app:ccp_showNameCode="false" app:ccp_showPhoneCode="true" /> <com.coomotravel.app.utils.customviews.CustomEditText android:id="@+id/et_phone_number" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:digits="0123456789" android:ellipsize="end" android:imeOptions="actionDone" android:inputType="phone" android:paddingEnd="@dimen/_8sdp" android:textColor="@color/white" android:textSize="@dimen/_15ssp" android:theme="@style/EditTextBackgroundTint" app:customFont="Avenir-Medium.ttf" /> </LinearLayout>
and in onCreate() method ccp.registerCarrierNumberEditText(etPhoneNumber);
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/hbb20/CountryCodePickerProject/issues/374?email_source=notifications&email_token=ABFQ32A6OZJQPJWWEUL7KPTRBT655A5CNFSM4KRJK2U2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4ILXB5DA, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFQ32GGHBFBHGRLDN5RER3RBT655ANCNFSM4KRJK2UQ .
@hbb20 it worked by adding android:editable="false"
strange!