Use String#replaceAll()
and match the .
more than one times in the string.
txtLdays.setText(txtLdays.getText().toString().replaceAll("([\\.]{2,})", "."));
Question
I want to replace the value in an editText if user enter two decimal points by mistake
else if(txtLdays.getText().toString().trim().contains(".."))
{
txtLdays.requestFocus();
txtLdays.setError("Double decimal ?");
// something like this
?? txtLdays.replaceWith(".." , ".");
return false;
}
La solution
Use String#replaceAll()
and match the .
more than one times in the string.
txtLdays.setText(txtLdays.getText().toString().replaceAll("([\\.]{2,})", "."));