Here Below I have mentioned my code.
Declare This under Oncreate
TextView TxtDocPhone=(TextView)findViewById(R.id.TxtDocPhone);
String numbersOnly = keepNumbersOnly(Phone);
String ProviderPhone = formatNumbersAsCode(numbersOnly);
Then call it
private String keepNumbersOnly(CharSequence s) {
return s.toString().replaceAll("[^0-9]", "");
}
private String formatNumbersAsCode(CharSequence s) {
int groupDigits = 0;
String tmp = "";
for (int i = 0; i < s.length(); ++i) {
tmp += s.charAt(i);
++groupDigits;
if (groupDigits == 3) {
tmp += "-";
// tmp += "";
groupDigits = 0;
}
}
return tmp;
}
Please guide me the correct way to achieve my objective.