Android Calculator - Editview Cannot Input Decimal Places
I am new to Android code development...I am developing a Android calculator apps and does not understand why the two EditTexts (first input and second input) cannot accept decimal
Solution 1:
If you want to use Decimal Number only on your EditText
use the xml attribute android:inputType="numberDecimal"
in your EditText widget your EditText declaration will be like this:
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal" />
If you want to use Signed Decimal Number than combine the two Xml attributes android:inputType="numberDecimal"
and android:inputType="numberSigned"
. Your EditText declaration will be like this:
<EditTextandroid:id="@+id/editText1"android:layout_width="match_parent"android:layout_height="wrap_content"android:ems="10"android:inputType="numberDecimal|numberSigned" ></EditText>
Solution 2:
Change android:inputType from "number" to "numberDecimal". See the documentation for even more options for inputType.
Solution 3:
inputType="number" doesnt allow floats. try changing:
android:inputType="number"
to:
android:numeric="integer|decimal"
Solution 4:
You need to change the input type of your EditText in the XML code.
Change the inputType attribute of the EditText from
android:inputType="number"
to
android:inputType="numberDecimal"
<EditText
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:inputType="numberDecimal"
android:id="@+id/txtOpd1"/>
Post a Comment for "Android Calculator - Editview Cannot Input Decimal Places"