I have a edit Text.I don't want the first letter to be space. If user hit the space as first letter cursor should not move.
Create a TextWatcher like this
public class MyTextWatcher implements TextWatcher {
private EditText editText;
public MyTextWatcher(EditText editText) {
this.editText = editText;
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String text = editText.getText().toString();
if (text.startsWith(" ")) {
editText.setText(text.trim());
}
}
@Override
public void afterTextChanged(Editable s) {
}
}
And add this to your EditText
editText.addTextChangedListener(new MyTextWatcher(editText));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With