Вопрос

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;
             }
Это было полезно?

Решение

Use String#replaceAll() and match the . more than one times in the string.

 txtLdays.setText(txtLdays.getText().toString().replaceAll("([\\.]{2,})", "."));
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top