Tuesday, 15 May 2012

android - Show a toast message when entering a number in Edit text -



android - Show a toast message when entering a number in Edit text -

i'd show toast message when entering number less 180 , i'm beginner need help , want show specific message when entering number less 180 , write in if method ?

public class mainactivity extends activity { edittext ed1; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); ed1 = (edittext)findviewbyid(r.id.edittext1); } public void mansaf (view v) { if (){ toast.maketext(mainactivity.this, "message1", toast.length_long).show(); } else toast.maketext(mainactivity.this, "message2 ", toast.length_long).show(); } }

and xml code :

<edittext android:id="@+id/edittext1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputtype="number" android:hint="ما السرعة التي تقود بها عادة ؟" > <requestfocus /> </edittext> <button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="ما مستوى قيادتي ؟" android:onclick="mansaf"/>

compare text 180 by:

if(integer.valueof(ed1.gettext().tostring())<180) toast.maketext(getbasecontext(),"message",tosat.length_long).show();

android if-statement numbers toast

No comments:

Post a Comment