android - EditText always showing null -


my xml

<textview          android:id="@+id/newplacelatlable"         android:text="place latitude"         android:layout_width="150dp"         android:layout_height="40dp"        android:layout_below="@id/newplacelable"/>     <edittext         android:id="@+id/newplacelat"         android:layout_width="150dp"         android:layout_height="40dp"         android:layout_torightof="@id/newplacelatlable"           android:layout_below="@id/newplacelable"          android:inputtype="numberdecimal"         />     <textview          android:id="@+id/newplacelonlable"         android:text="place longitude"         android:layout_width="150dp"         android:layout_height="40dp"        android:layout_below="@id/newplacelatlable"/>     <edittext         android:id="@+id/newplacelon"         android:layout_width="150dp"         android:layout_height="40dp"         android:layout_torightof="@id/newplacelonlable"          android:layout_below="@id/newplacelatlable"         android:inputtype="numberdecimal"         /> 

and in code

if (et1.gettext().tostring().matches(""))             toast.maketext(getapplicationcontext(), "name can't null", toast.length_short).show();         else if (et2.gettext().tostring().matches(""))             toast.maketext(getapplicationcontext(), "latitute can't null", toast.length_short).show();         else  if (et3.gettext().tostring().matches(""))             toast.maketext(getapplicationcontext(), "longitute can't null", toast.length_short).show(); 

where et1, et2 , et3 are

protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_change);         et1 = (edittext) findviewbyid(r.id.newplacetext);                  et2 = (edittext) findviewbyid(r.id.newplacelat);          et3 = (edittext) findviewbyid(r.id.newplacelon); 

but every time run app ,it gives toast "latitute can't null". although et2 has text in it, didn't show here. kindly in it. what's problem

you want check edittext filled same value.

matches("") 

is not need.

check if lenght of string > 0, or use equals("")

if (et1.gettext().tostring().length() <= 0)             toast.maketext(getapplicationcontext(), "name can't null", toast.length_short).show(); else if (et2.gettext().tostring().length() <= 0)             toast.maketext(getapplicationcontext(), "latitute can't null", toast.length_short).show(); else  if (et3.gettext().tostring().length() <= 0)             toast.maketext(getapplicationcontext(), "longitute can't null", toast.length_short).show(); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -