<EditText
android:id="@+id/edtxt1"
android:layout_below="@+id/txt1"
android:layout_width="fill_parent"
android:gravity="center_horizontal"
android:maxLength="15"
android:textColor="#ffffff"
android:paddingTop="10dp"
android:layout_marginLeft="30dp"
android:background="@drawable/edittxt"
android:inputType="numberDecimal"
android:layout_centerInParent="true"
android:layout_height="50dp" />
I have a unit converter app. Everything works fine, but the only problem I have is if the user enter only a decimal point "."
in the EditText and tries to convert one parameter to another, the app crashes!
How could I detect if only a decimal point is entered (ie. without the numbers; like "."
is entered instead of "3.03"
or ".3"
).
I used the code below to detect if the EditText is empty when the user is trying to convert from one parameter to another, but it doesn't work for decimal point.
if (cel1.matches(""))
{
Toast.makeText(getApplicationContext(), "Enter the content!",
Toast.LENGTH_LONG).show();
}
if (cel1.equals("") || cel1.equals("."))
? – Elliott Frisch