Reputation: 940
I am trying to get the inputType=phone to work consistently. It works perfectly in one project, but I can't get it to work in any other project. By "work", I mean that the number is not formatted as the value is typed. Here's a test project that does not work.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
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="com.jdot.testphoneinput2.MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:id="@+id/editText"
android:hint="enter phone" />
</RelativeLayout>
Here's the class declaration:
package com.jdot.testphoneinput2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Notes:
Upvotes: 3
Views: 3703
Reputation: 648
You are probably forgetting something like this in your activity:
editText.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
android:inputType="phone"
doesn't format your input, it simply limits the set of symbols that can be entered.
Upvotes: 6