Android Calculator - Editview cannot input decimal places

前端 未结 4 1935
醉话见心
醉话见心 2021-01-24 10:56

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 decim

相关标签:
4条回答
  • 2021-01-24 11:33

    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"/>
    
    0 讨论(0)
  • 2021-01-24 11:35

    inputType="number" doesnt allow floats. try changing:

    android:inputType="number"
    

    to:

    android:numeric="integer|decimal"
    
    0 讨论(0)
  • 2021-01-24 11:45

    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:

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="numberDecimal|numberSigned" >
    
    </EditText>
    
    0 讨论(0)
  • 2021-01-24 11:57

    Change android:inputType from "number" to "numberDecimal". See the documentation for even more options for inputType.

    0 讨论(0)
提交回复
热议问题