Step-1: Add "implements TextWatcher" after Activity
eg. public class AddMoreWebsite extends Activity implements TextWatcher {
Step-2:Now Put Cursor on Red line error and Add UnImplemented methods of TextWatcher.
Eg. it Will add following Methods
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
String result = s.toString().replaceAll(" ", "");
if (!s.toString().equals(result)) {
et_AddMoreSite.setText(result);
et_AddMoreSite.setSelection(result.length());
}
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
Step-3: Now Add following lines in afterTextChanged(...)
String result = s.toString().replaceAll(" ", "");
if (!s.toString().equals(result)) {
et_AddMoreSite.setText(result);
et_AddMoreSite.setSelection(result.length());
Step-4: Now Put this line in onCreate() after your editText declaration.
et_AddMoreSite.addTextChangedListener(this);
Ref. Link: http://stackoverflow.com/questions/9757991/how-to-delete-instantly-space-from-an-edittext-if-a-user-presses-the-space
Enjoy.....