**`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
}
});