java - Toast Won't show on android application, using android studio -


good morning, tried getting toast show if number of students less 0, or greater 100. app seems work fine, except showing toast. assignment due tomorrow night.

here code:

package co.tekitall.classroommanager;   import android.support.v7.app.appcompatactivity;   import android.os.bundle;   import android.view.view;   import android.view.view.onclicklistener;   import android.widget.button;   import android.widget.edittext;   import android.widget.toast;    import java.util.arraylist;    import static co.tekitall.classroommanager.r.id.numofstudents;    public class classroom extends appcompatactivity {      @override     public void oncreate(bundle savedinstancestate) {       super.oncreate(savedinstancestate);       setcontentview(r.layout.activity_classroom);       button button = (button) findviewbyid(r.id.submitclassroominfobutton);      }      void classroomelements() {       //arraylist       arraylist<edittext> arraylist = new arraylist<>();       arraylist.add((edittext) findviewbyid(r.id.teacher_name));       arraylist.add((edittext) findviewbyid(r.id.room_number));       arraylist.add((edittext) findviewbyid(r.id.classroomhelper));       arraylist.add((edittext) findviewbyid(r.id.numofstudents));     }      onclicklistener listener = new onclicklistener() {       @override       public void onclick(view v) {         edittext numofstudents = (edittext) findviewbyid(r.id.numofstudents);         string getstucount = numofstudents.gettext().tostring();          int setstucount = integer.parseint(getstucount);          if(setstucount < 0) {            numofstudents.settext("");           toast toast = toast.maketext(classroom.this, "please try again! number must greater 0 , less 100...", toast.length_long);           toast.show();          }          if(setstucount > 100) {            numofstudents.settext("");           toast toast = toast.maketext(classroom.this, "please try again! number must greater 0 , less 100...", toast.length_long);           toast.show();          } else           numofstudents.settext("");           toast toast = toast.maketext(classroom.this, "good job",            toast.length_long);           toast.show();         }     };   } 

you need bind button , listener using

@override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_classroom);     button button = (button) findviewbyid(r.id.submitclassroominfobutton);     button.setonclicklistener(listener);     // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ } 

plus use if , else-if instead of multiple ifs because number can either less 0 otherwise greater 100 or between|equals 0 or 100

if(setstucount < 0){//...code} else if(setstucount > 100){//...code} else  {//...code} 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -