Dismiss Custom Alert Dialog on Back button pressed of hardware in android -


i having problem on button of hardware. in main activity, have 1 list view(say 1). when click on item of list view(1), 1 alert dialog appears, in alert dialog, there 1 list view(say 2). data of list view(2) being repeated when press button of hardware. have put cancel image on alert dialog dismiss, when press cancel image, data not being repeated. tried different methods onresume(), onpause(), ondestroy(), onrestart() clear array list view(2), nothing works. here code...

case list_dialog : layoutinflater inflater2 = layoutinflater.from(this); view dialogview1 = inflater2.inflate(r.layout.listdialog, null); alertdialog.builder dialogbuilder2 = new alertdialog.builder(this); dialogbuilder2.setview(dialogview1); dialogdetails = dialogbuilder2.create();   case list_dialog:      alertdialog alertdialog1 = (alertdialog) dialog;      // cancel alert dialog     imageview ivcancel = (imageview) alertdialog1.findviewbyid(r.id.imgcancel);     ivcancel.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {             // todo auto-generated method stub             dismissdialog(list_dialog);              arr2.clear();         }     });      // friend list     showfriendlist();     break; 

// list view data inserted function call private void showfriendlist() { // todo auto-generated method stub request.executemyfriendsrequestasync(friendsession, new graphuserlistcallback() {

            @override             public void oncompleted(list<graphuser> users, response response) {                 // todo auto-generated method stub              //  arr2 = new arraylist<string>();                 for(graphuser user : users)                 {                     arr2.add(user.getname());                 }                  adapter2 = new arrayadapter<string>(getbasecontext(), r.layout.single_row, r.id.txt,arr2);                 lvdialog.setadapter(adapter2);                 lvdialog.setchoicemode(listview.choice_mode_multiple);                 adapter2.notifydatasetchanged();                  itemcount = lvdialog.getcount();                 toast.maketext(getbasecontext(), "" + itemcount, 1000).show();              }         });           } 

// tried these methods, nothing works...

@override       public void onresume()       {           super.onresume();           showsavedfiles();           arr2.clear();        }      @override     public void onpause()     {         super.onpause();         arr1.clear();         arr2.clear();     }       @override     public void onbackpressed() {     //super.onbackpressed();     // finish activity      arr2.clear();      return;     }    @override    public boolean onkeydown(int keycode, keyevent event) {    if (keycode == keyevent.keycode_back) {         arr2.clear();         dismissdialog(list_dialog);       }     return false; } 

i'm not sure might adding following code onkeydown method might out :

return super.onkeydown(keycode, event); 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -