android - Closing alert dialog using menu -


i have alert dialog items. need close dialog when user clicks menu button without giving options close. how can that?

here code

charsequence[] cs = ques_cat.toarray(new charsequence[ques_cat.size()]); finalcharsequence[]css=ques_catidtoarray(newcharsequence[ques_catid.size()]);  alertdialog.builder builder = new alertdialog.builder(gropinion_questions.this); builder.settitle("choose category"); builder.setitems(cs, new dialoginterface.onclicklistener()  {     public void onclick(dialoginterface dialog, int item) {         string ss = css[item].tostring();         getsubcat(ss);     } }); alertdialog alert = builder.create(); alert.show();  public boolean oncreateoptionsmenu(menu menu) {     menuinflater menuinflater=getmenuinflater();     menuinflater.inflate(r.menu.activity_main, menu);     if(alert !=null && alert.isshowing())         alert.dismiss();     return true; } 

on host activity's, want check if user has gone menu , dismiss dialog there:

@override public boolean oncreateoptionsmenu(menu menu) {     yourdialog.dismiss();     return true; } 

or may intercept menu key pressed event adding main activity:

public boolean onkeyup(int keycode, keyevent event) {     if (keycode == keyevent.keycode_menu) {         if (yourdialog != null && yourdialog.isvisible()) {             yourdialog.dismiss();         }         return true;     } else {         return super.onkeyup(keycode, event);     } } 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -