How can EditText accept only integer or float value?
Use Java
for input both integer and floatedit.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
for input only integeredit.setInputType(InputType.TYPE_CLASS_NUMBER);
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>