user820913
user820913

Reputation: 619

Android EditText does not take period

I have an EditText-window which when I type a double number for example 0,01 displays 001), it will not take the period (comma) sign (oper2 representing operand2). What is strange is that the EditText window over it (oper1 representing operand2) takes period. As far as I can see it has exactly the same code. Can anyone tell me what is wrong? Here is the relevant java code:

if ((operand1.getText().length() > 0) && (operand2.getText().length() > 0)) {
                double oper1 = Double.parseDouble(operand1.getText().toString());
                double oper2 = Double.parseDouble(operand2.getText().toString());
                double theResult = ((oper2 * oper1 * 60) / 40);
                String stringResult = String.format("%.2f", theResult);
                mlHour.setText(stringResult + " ml/t");
            } else {
                Toast.makeText(AdrenalinActivity.this, getString(R.string.toastNoradrenalin), Toast.LENGTH_LONG).show();
            }
        }
    });

Upvotes: 0

Views: 182

Answers (1)

MikeT
MikeT

Reputation: 56983

In the XML for the EditText, if you have android:inputType="number" that would only allow numerics, I believe.

If so change to android:inputType="numberDecimal"

You may also want to compliment this with android:digits="0123456789." (this limits the input to only use those digits (eg comma, - (negative) would not be able to be typed).

Upvotes: 3

Related Questions