It is necessary to organize the input check in the text field by the filter.

+Х(ХХХ) ХХХ-ХХХХ

The ideal scenario is as follows. Initially, the input text looks like this:

+_ ( _ _ _ ) _ _ _-_ _ _ _ .

The user enters only the numbers and they fall into place. Those. after the first digit will be like this:

+7 ( _ _ _ ) _ _ _-_ _ _ _

Second:

+7 (4 _ _ ) _ _ _-_ _ _ _ , etc.

Help with the implementation, examples of ideas ... I found it myself: using a mask with EditText , but I can't bring it to mind.

 package my.dfedorenko; import android.app.Activity; import android.os.Bundle; import android.widget.EditText; public class TestPhoneparserActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); EditText phone = (EditText)findViewById(R.id.phone); phone.addTextChangedListener(new MaskedWatcher("(###) ###-##-##")); setContentView(R.layout.main); }} 

    1 answer 1

    The simplest thing that comes to mind is to cut the text .substring () , then you need to look at how input is generally implemented through which widgets? Or just a string ...

     import android.app.Activity; import android.os.Bundle; import android.widget.EditText; public class TestPhoneparserActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); EditText phone = (EditText)findViewById(R.id.phone); phone.addTextChangedListener(new MaskedWatcher("(###) ###-##-##")); }} 
    • in plain text field. - or8it
    • Well, so far, nothing beautiful has come up with, except for - just changing _ by the digit on the position index - Gorets
    • By the way, about the post that you found - everything is simple, just copy-paste and indicate the mask for which you want to adjust the result. - Gorets
    • When I try to start something that I found the application crashes, I'm looking for the reason. - or8it
    • what logs say? - Gorets