java - Call dialog.dismiss after the successful login toast message which will hide the dialog -


can show me how dismiss dialog because trying dialog.dismiss() , alertdialog.dismiss getting error cannot resolve symbol , access , use input email , password

package com.example.marcusgrant.test12345;  import android.os.bundle; import android.support.annotation.nullable; import android.support.v7.app.alertdialog; import android.support.v7.app.appcompatactivity;  import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.imageview; import android.widget.toast;  public class console_activity extends appcompatactivity {  @override protected void oncreate(@nullable bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.console_login);       final imageview xshowdialog = (imageview) findviewbyid(r.id.xboximbtn);       imageview pshowdialog = (imageview) findviewbyid(r.id.psnimbtn);       xshowdialog.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             alertdialog.builder mbuilder = new alertdialog.builder(console_activity.this);             view mview = getlayoutinflater(). inflate(r.layout.xdialog_signin, null);              final edittext xemail = (edittext) mview.findviewbyid(r.id.etemail);             final edittext xpassword = (edittext) mview.findviewbyid(r.id.etpassword);             button xlogbtn = (button) mview.findviewbyid(r.id.logbtn);             button xntnbtn = (button) mview.findviewbyid(r.id.ntnbtn);              xlogbtn.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view v) {                     if(!xemail.gettext().tostring().isempty() && !xpassword.gettext().tostring().isempty())                     {                         toast.maketext(console_activity.this, r.string.successful_login, toast.length_short).show();                         xshowdialog.setimageresource(r.drawable.xboxbuttongreen);              //cannot resolve symbol 'alertdialog'              dialog.dismiss();                       }                     else                     {                         toast.maketext(console_activity.this, r.string.error_login_message, toast.length_short).show();                     }                 }             });                 xntnbtn.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view v) {                       //cannot resolve symbol 'alertdialog'                     alertdialog.dismiss();                 }             });                mbuilder.setview(mview);             alertdialog dialog = mbuilder.create();             dialog.show();          }     });  }      } 

you need declare variable before use it. code, inside oncreate() gets executed sequentially , therefore have declare dialog variable before using ..

change code :

        ...         final edittext xemail = (edittext) mview.findviewbyid(r.id.etemail);         final edittext xpassword = (edittext) mview.findviewbyid(r.id.etpassword);         button xlogbtn = (button) mview.findviewbyid(r.id.logbtn);         button xntnbtn = (button) mview.findviewbyid(r.id.ntnbtn);          // changes here         mbuilder.setview(mview);         final alertdialog dialog = mbuilder.create();           xlogbtn.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 if(!xemail.gettext().tostring().isempty() && !xpassword.gettext().tostring().isempty())                 {                     toast.maketext(console_activity.this, r.string.successful_login, toast.length_short).show();                     xshowdialog.setimageresource(r.drawable.xboxbuttongreen);            dialog.dismiss();                   }                 else                 {                     toast.maketext(console_activity.this, r.string.error_login_message, toast.length_short).show();                 }             }         });             xntnbtn.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                   //changes here                 dialog.dismiss();             }         });          //changes here         dialog.show();      } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -