How to insert number (double) into EditText

I am using this code

 <EditText
     android:id="@+id/price_for_liter_value_edit_text"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:background="@android:color/transparent"
     android:textColor="@color/dn_14_date"
     android:fontFamily="sans-serif-regular"
     android:textSize="18sp"
     android:text=""
     android:padding="4dp"
     android:inputType="number"/>

      

and on this line I am setting inputType:

  android:inputType="number"

      

but I cannot enter a double number (c. - like 1.3 or 20.5). What type should I use in inputFormat?

+3


source to share


3 answers


you can use



  android:inputType="numberDecimal"

      

+13


source


You can see this reference for all variations of the valid input type. In your case

android:inputType="numberDecimal"

      



or

int type = InputType.TYPE_CLASS_NUMBER |  InputType.TYPE_NUMBER_FLAG_DECIMAL;

((EditText)findViewById(R.id.price_for_liter_value_edit_text)).setInputType(type);

      

+6


source


There is a digit attribute for Edittext : -

 android:digits="0123456789." 

      

If this parameter is set, indicates that this TextView has a numeric input method and that these specific characters are the ones to accept. [string] - Text fragment from developer.android.com

This will only allow numbers and "." to add to the text box

+3


source







All Articles