【问题标题】:Android Phone Number FormatAndroid 电话号码格式
【发布时间】:2016-05-04 21:08:11
【问题描述】:
**`I want to develop an edit text which saprates the phone number

在 x-xxx-xxx-xxxx 这种格式中。确保我不想附加 - 在数之间。它应该看起来像四个不同的编辑文本和 进入每个块后,焦点会自动更改为下一个,例如 信用卡付款`。**

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

     <EditText
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="" 
        android:inputType="number"
        android:maxLength="15"
        android:layout_marginBottom="5dp"/>
</RelativeLayout>

这里是相关的活动代码-

  test.addTextChangedListener(new TextWatcher() {
                 private boolean mFormatting;
                 private int mAfter;
                @Override
                public void afterTextChanged(Editable s) {
                    // TODO Auto-generated method stub
                     if (!mFormatting) {
                         mFormatting = true;
                     }
                     if(mAfter!=0) 
                            PhoneNumberUtils.formatNumber(s,PhoneNumberUtils.getFormatTypeForLocale(Locale.US));                             
                                     mFormatting = false;
                }

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count,
                        int after) {
                    // TODO Auto-generated method stub
                     mAfter  =   after;
                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before,
                        int count) {
                    // TODO Auto-generated method stub

                }

            });

【问题讨论】:

  • 用您项目中的代码示例更新您的答案。尝试包含演示您的特定问题所需的最少代码。
  • 另外,您的问题确实很广泛。您应该专注于将问题进一步分解为更小的功能,例如:“在输入不同的文本视图后如何聚焦文本视图”

标签: android


【解决方案1】:

尝试实现TextWatcher。 http://developer.android.com/reference/android/text/TextWatcher.html

您可以在此处获得更多详细信息。 https://stackoverflow.com/a/19442743/5829624

已编辑

由于您已经实现了 TextWatcher(我在发布答案后看到了它),所以第二个链接肯定会对您有所帮助。

【讨论】:

    猜你喜欢
    • 2013-03-07
    • 1970-01-01
    • 1970-01-01
    • 2012-12-17
    • 2014-04-01
    • 2012-08-11
    • 2012-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多