Fred J. Fred J. - 20 days ago 4
Android Question

android:inputType="numberDecimal" vs. InputType.TYPE_NUMBER_FLAG_DECIMAL

The following condition evaluates to false. Isn't suppose to be true?

editText.getInputType() == InputType.TYPE_NUMBER_FLAG_DECIMAL


specially when in the xml file, I have

android:inputType="numberDecimal"


Debugging shows that

editText.getInputType() = 8194


and

InputType.TYPE_NUMBER_FLAG_DECIMAL = 8192


What am I missing?

Answer

numberDecimal refers to both TYPE_CLASS_NUMBER and TYPE_NUMBER_FLAG_DECIMAL. So when you compare, you need to do this.

editText.getInputType() == (InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER)
Comments