onclick - Android setOnClick not working/Dialogbox not appearing -


app launches fine when click on select_players button, dialog box doesn't appear on device. here's code:

public class mainactivity extends activity {       private button selectplayers;              @override         protected void oncreate(final bundle savedinstancestate) {              super.oncreate(savedinstancestate);             setcontentview(r.layout.activity_demo);              super.onstart();    //customize             super.onresume();   //customize              selectplayers = (button) findviewbyid(r.id.add_players);              selectplayers.setonclicklistener(new view.onclicklistener() {                  @override                 public void onclick(view view) {                      // launch dialogbox on click                     oncreatedialog(savedinstancestate);                  }             });         }          public dialog oncreatedialog(bundle savedinstancestate) {              @suppresswarnings("rawtypes")             final arraylist mselecteditems = new arraylist();  // track selected items             alertdialog.builder builder = new alertdialog.builder(this);             // set dialog title             builder.settitle(r.string.select_players)              // specify list array, items selected default (null none),             // , listener through receive callbacks when items selected             .setmultichoiceitems(r.array.players_name, null,                     new dialoginterface.onmultichoiceclicklistener() {                  @suppresswarnings("unchecked")                 @override                 public void onclick(dialoginterface dialog, int which,                         boolean ischecked) {                     if (ischecked) {                         // if user checked item, add selected items                         mselecteditems.add(which);                     } else if (mselecteditems.contains(which)) {                         // else, if item in array, remove                          mselecteditems.remove(integer.valueof(which));                     }                 }             })              // set action buttons             .setpositivebutton(r.string.ok, new dialoginterface.onclicklistener() {                  @override                 public void onclick(dialoginterface dialog, int id) {                      //code close dialogbox , start forge                  }             })             .setnegativebutton(r.string.cancel, new dialoginterface.onclicklistener() {                  @override                 public void onclick(dialoginterface dialog, int id) {                      //code close dialogbox                  }             });              return builder.create();         } } 

i see dialog method returns dialog i'm not sure how make appear result of onclick? (for reference, took dialog method android dev. website.)

thank you!

this method returns dialog , have build 1 in onclick

     dialog d = oncreatedialog(savedinstancestate);      d.show(); 

i think had tried override activity method oncreatedialog(), have in antoher way, shown here:

http://www.mysamplecode.com/2011/11/android-alertdialog-example-showdialog.html


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -