0
**`I want to develop an edit text which saprates the phone number

in x-xxx-xxx-xxxx this format.make sure I do not want to append - in between the number. it should look like four different edit text and after entering on each block focus automatically changes to next such as credit card payments`.**

<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>

here is related activity code-

  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

                }

            });
  • 1
    update your answer with code examples from your project. try to include the minimal amount of code necessary to demonstrate your specific question. – activedecay Jan 27 '16 at 18:41
  • also, your question is really quite broad. you should focus on breaking the problem down further into smaller pieces of functionality, like: "how to focus a textview after a different textview is typed into" – activedecay Jan 27 '16 at 18:42

1 Answers1

0

Try to implement TextWatcher. http://developer.android.com/reference/android/text/TextWatcher.html

You can get some more details here. https://stackoverflow.com/a/19442743/5829624

Edited

As you already have implemented TextWatcher (I have seen it after posting my answer), the second link surely going to help you.

Community
  • 1
  • 1
Sudip Podder
  • 830
  • 11
  • 25