【发布时间】:2019-04-19 21:36:58
【问题描述】:
我在我的 editText 字段上使用 PhoneNumberFormattingTextWatcher 我注意到它不会格式化以 11 开头的数字,而是将它们视为普通字符串。为什么是这样。有没有办法解决这个问题?
这是 XML:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="8">
<!-- INPUT -->
<EditText
android:id="@+id/etMobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/dp_size_8"
android:layout_marginBottom="@dimen/dp_size_8"
android:background="@null"
android:ems="10"
android:hint="@string/edt_mobile"
android:inputType="phone"
android:maxLength="14"
android:paddingTop="@dimen/dp_size_2" />
</android.support.design.widget.TextInputLayout>
这是java活动中的用法:
etMobile.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
当前本地是
美国
预期的数字格式是
1 222-222-2222
1 333-333-3333
但是当一个“1”跟在最初的“1”之后时,我得到了
11111111111111
【问题讨论】:
-
显示 EditText 的 XML 代码
-
请显示代码、输入文本、当前输出文本、预期输出文本、您运行的 android 版本、系统中设置的语言/区域设置。请更新您的问题并回答所有个问题,以便我们弄清楚发生了什么。
-
@EugenPechanec 完成
-
@PankajKumar 完成
标签: android