Enter decimal point in an edittext

0

I have a problem, in an app of a calculator in android studio, simple, I have 2 EditText and that I enter numbers of phone(InputType="Phone") , for more than I have tried I do not know how to limit that only one point can be entered decimal

Thank you in advance.

What I tried:

switch (view.getId()){
    case R.id.suma:
        String aux1=numero1.getText().toString();
        String aux2=numero2.getText().toString();
        String rta="";
        float result = 0;
        if (numero1.getText().toString().contains(".")){

            rta="Tiene un punto";
            resultado1.setText("Hey"+ rta);
        break;}
        else {
            float numero1 = Float.parseFloat(aux1);
            float numero2 = Float.parseFloat(aux2);
            result = numero1 + numero2;
            resultado1.setText("tu" + result);
            break;
}
  • List item
  • asked by Rafael Alejandro Luna Lomeli 24.12.2017 в 05:59
    source

    1 answer

    0

    I understand that the same InputType = Phone provides you the option to do that, you do not need to program something else for it, also try to put this in the EditText XML:

    android:digits="1234567890.-"
    

    Try with that and let me know what happens ...

        
    answered by 24.12.2017 в 17:37