Can anybody help me to solve this problem.? I have added Dash(-) between phone numbers. Here Below I have mentioned my code.
// Removing from here
Now I want to remove dash(-) when I press back button. In my case I can't able to do that. Let's say If I have insert 3 character, then Dash will automatically add after that three numbers, then if I press back button I am not able to delete dash and even that three number which are before dash.
I had to select all of the text and then I would have to press delete then and then It's going to delete.. But with backspace I Can't delete that.. So how can I do that. Can anybody give me code answer of this..??
Thanks in advance, JT.
Updating from here
public class MainActivity extends Activity {
EditText inputPhone;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create_new_member);
inputPhone = (EditText) findViewById(R.id.phoneText);
inputPhone.addTextChangedListener(new TextWatcher() {
int len = 0;
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
String str = inputPhone.getText().toString();
if ((str.length() == 3 && len < str.length()) || (str.length() == 7 && len < str.length())) {
inputPhone.append("-");
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
String str = inputPhone.getText().toString();
len = str.length();
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
}
}