I want to add hyphen in between contact umber automatically when user enters it at runtime & also it should remove it automaticaly,
like 904-149-0646
i'm using this code,
package com.cssoft.hyphen;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText edit_number;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edit_number=(EditText)findViewById(R.id.edit_number);
putHyphen();
}
public void putHyphen(){
edit_number.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
int len=find(Integer.parseInt(s.toString()));
if(len==3||len==6){
edit_number.setText(s+"-");
}
}
});
}
public int find(int num) {
int len = 0;
while (num != 0) {
num = num / 10;
len++;
}
return len;
}
}
please give me solutions as soon as possible.