Reputation: 4639
I use 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 at this line I set inputType:
android:inputType="number"
but I cant enter double number (with . - like as 1.3 or 20.5). What type should I use in inputFormat ?
Upvotes: 11
Views: 21064
Reputation: 1890
You can see this reference for all variations of allowed inputType. 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);
Upvotes: 11
Reputation: 5295
For Edittext, there is an attribute digits :-
android:digits="0123456789."
If this param is set, specifies that this TextView has a numeric input method and that these specific characters are the ones that it will accept. [string] - Text snippet from developer.android.com
This will allow only numbers and "." to be added in the textview
Upvotes: 6