java - How to make alert dialog appear only once when dragging the seek bar -


ok when pull seek bar alert dialog freaks out , comes multiple times on avd. how fix when there no user input in etcash alert dialog shows on screen once. keep on prompting user invalid input until user inputs in edittext created. suggestion!!! have tried no avail !!

import java.text.decimalformat;  import junit.framework.assert; import android.os.bundle; import android.app.activity; import android.app.alertdialog; import android.content.context; import android.content.dialoginterface; import android.text.editable; import android.text.textwatcher; import android.view.view; import android.widget.button; import android.widget.edittext;  import android.widget.seekbar; import android.widget.textview;  public class mainactivity extends activity {    private seekbar sbcash; private button btnten,btntwenty,btnthirty; private textview tvshwprog,tvfinal; private edittext etcash;   @override public void oncreate(bundle savedinstancestate) {       super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      etcash = (edittext)findviewbyid(r.id.etcash);     sbcash = (seekbar)findviewbyid(r.id.sbcash);     tvshwprog = (textview)findviewbyid(r.id.tvshwprog);     tvfinal = (textview)findviewbyid(r.id.tvfinal);     btnten = (button)findviewbyid(r.id.btnten);     btntwenty = (button)findviewbyid(r.id.btntwenty);     btnthirty = (button)findviewbyid(r.id.btnthirty);         etcash.addtextchangedlistener(new textwatcher(){          public void aftertextchanged(editable arg0)          {           }         public void beforetextchanged(charsequence arg0, int arg1,int arg2, int arg3)          {          }         public void ontextchanged(charsequence arg0, int arg1, int arg2,int arg3) {              try{                   guichanged();                 }                 catch(exception e)                 {                     e.printstacktrace();                     alertdialog alert =errormessage();                     alert.show(); //<<< show alertdialog here                 }         }       });       seekbar.onseekbarchangelistener sblistener = new seekbar.onseekbarchangelistener()      {         public void onstoptrackingtouch(seekbar seekbar) {          }          public void onstarttrackingtouch(seekbar seekbar) {}         public void onprogresschanged(seekbar seekbar, int progress, boolean fromuser)          {             try{             guichanged();             }             catch(exception e)             {                 e.printstacktrace();             }         }       };     sbcash.setonseekbarchangelistener(sblistener);      dosomethig();     dosomethig2();     dosomething3();     }  public alertdialog errormessage() {     // use builder class convenient dialog construction     alertdialog.builder builder = new alertdialog.builder(mainactivity.this);     builder.setmessage("enter number!!!!")            .setnegativebutton("fix", new dialoginterface.onclicklistener() {                public void onclick(dialoginterface dialog, int id) {                    // user cancelled dialog                }            });     // create alertdialog object , return     return builder.show(); }   public void guichanged() {         try{             decimalformat fmt = new decimalformat ("0.00");              int cashmoney = sbcash.getprogress();              tvshwprog.settext("current percentage " +cashmoney+ "%");              double amount = double.parsedouble(etcash.gettext().tostring());              double moneydue = (amount * (cashmoney/100.0));              double totalamount = (moneydue + amount);              tvfinal.settext("tip " + fmt.format(moneydue)+ " total "+ fmt.format(totalamount));         }         catch(exception e)         {             e.printstacktrace();              alertdialog alert = errormessage();             alert.show();             if(alert.isshowing())             {                 alert.cancel();             }         }  }   public void dosomethig() {      btnten.setonclicklistener(new view.onclicklistener() {          @override         public void onclick(view v) {             // todo auto-generated method stub              sbcash.setprogress(10);           }     }); } public void dosomethig2() {      btntwenty.setonclicklistener(new view.onclicklistener()      {          @override         public void onclick(view v) {             // todo auto-generated method stub              sbcash.setprogress(15);         }       }); } public void dosomething3() {     btnthirty.setonclicklistener(new view.onclicklistener() {          @override         public void onclick(view v) {             // todo auto-generated method stub              sbcash.setprogress(20);          }     }); } 


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -