I am trying to change space to % in my android code. My aim is like this:
when user writes for example "I am trying", after press spacebar instead a gap between words a % be written in myeditText; I mean like this: "I%am%trying"
I am trying to change space to % in my android code. My aim is like this:
when user writes for example "I am trying", after press spacebar instead a gap between words a % be written in myeditText; I mean like this: "I%am%trying"
Just implement a TextWatcher on your editText and inside its onTextChanged() method implements a simple if condition to check if space is entered or not and then replace that space with % if the condition is true.
try this,
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (charSequence.toString().equalsIgnoreCase(" ")) {
editText.setText(charSequence.toString().replace(" ", "%"));
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});