0

I am trying to write an app that includes an EditText that gets a number from the user and dials it. I am trying to use formatNumber to format it as a phone number but it is giving me an error.

//inputOne is the input from the EditText
inputOne = formatNumber(fieldOne.getText().toString()); 

It says that formatNumber takes a String as a parameter so I don't understand why I am getting an error.

I also tried using setInputType and I got a similar error (cannot find symbol: variable InputType) even though I imported android.widget.*;

fieldOne = (EditText) findViewById(R.id.input1);
fieldOne.setInputType(InputType.TYPE_CLASS_PHONE); 

I know that there is probably a painfully obvious solution but I don't know what it is!

Jacob Schoen
  • 14,034
  • 15
  • 82
  • 102
jacky
  • 195
  • 6
  • 17

2 Answers2

0

Perhaps you could use regular expression to get the format. Example: Regex.Replace("1112224444", @"(\d{3})(\d{3})(\d{4})", "$1-$2-$3");

Taken from this question: How to format a string as a telephone number in C#

Community
  • 1
  • 1
Calvin
  • 3,302
  • 2
  • 32
  • 41
0

You can add an attribute android:inputType="phone" in edittext. This might work with api-15

<EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="phone" >
</EditText>
prabhat
  • 273
  • 1
  • 7
  • I could use the RegEx but since the class already exists I would liek to use it. I also should have mentioned the fact that I am trying to use the same EditText for different types of input (phone number, string, etc.). Is that a sensible thing to do or should I just create separate EditTexts and use the above method? It seems like that could get pretty inefficient but perhaps that is how it is normally done. (Sorry if these are silly questions...I am new to Android and to programming in general). – jacky Mar 15 '12 at 06:05