android - DialogFragment's weird behavior -


i spent day trying make up, can't..

this problem: i want yes/no alertdialog doesn't disappear on orientation change, decided use dialogfragment.

so prepared code , for first use, perfect, if hit button (that should show dialog) once more (second, third , further times) dialog doesn't show up! though can see logs makes instances , have no errors, it's there, can't see it!

if fold app, or turn off / on screen (i believe it's calling onresume() method) dialogs shows up, of them (depending how time hit button), seems displaying issue or refreshing problem maybe.. don't know, came here hoping help.

about code:

i have listview custom adapter, , in adapter have code show alertdialog (dialogfragment) - part of imagebutton onclicklistener.

the code dialogfragment use:

  public static class cmydialogfragment extends dialogfragment {      public static cmydialogfragment newinstance(int title) {         cmydialogfragment frag = new cmydialogfragment();         bundle args = new bundle();         args.putint("title", title);         frag.setarguments(args);         return frag;     }      @override     public dialog oncreatedialog(bundle savedinstancestate) {         int title = getarguments().getint("title");         this.setcancelable(true);         setretaininstance(true);          return new alertdialog.builder(getactivity())                 //   .seticon(r.drawable.alert_dialog_icon)                 .settitle(title)                 .setpositivebutton(r.string.yes,                         new dialoginterface.onclicklistener() {                             public void onclick(dialoginterface dialog, int whichbutton) {                                 ((actaudiorecords) getactivity()).dopositiveclick();                             }                         }                 )                 .setnegativebutton(r.string.no,                         new dialoginterface.onclicklistener() {                             public void onclick(dialoginterface dialog, int whichbutton) {                                 ((actaudiorecords) getactivity()).donegativeclick();                             }                         }                 )                 .create();     } } 

the code calling dialog show (within custom listview adapter):

   public view getview(final int position, view convertview, viewgroup parent) {          view vi = convertview;         if (vi == null)             vi = inflater.inflate(r.layout.recordings_row, null);          textview tvdate = (textview) vi.findviewbyid(r.id.tv_recordings_r_date);         tvdate.settext(ainfo.get(position).getdate());          imagebutton ibtn_play = (imagebutton) vi.findviewbyid(r.id.ibtnplay);         final string localpath = dpath + file.separator + ainfo.get(position).getfname();          imagebutton ibtn_remove = (imagebutton) vi.findviewbyid(r.id.ibtnrecordings_r_remove);         ibtn_remove.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                 curfname = ainfo.get(position).getfname();                 curid = ainfo.get(position).getid();                  showdialog();             }         });           ibtn_play.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                 play(localpath);             }         });          return vi;     } 

the additional functions:

  void showdialog() {     dialogfragment newfragment = cmydialogfragment.newinstance(             r.string.do_you_want_to_remove_the_file);     newfragment.show(getfragmentmanager(), "dialog"); }  public void dopositiveclick() {     // stuff here.     ps_db.delete(const_audiorecords_tname, "id = " + curid, null);     new file(dpath + file.separator + curfname).delete();     toast.maketext(actaudiorecords.this, getstring(r.string.audiorecord_has_been_removed), toast.length_long).show();     actaudiorecords.this.oncreate(null); //restarting activity refresh lv      log.i("fragmentalertdialog", "positive click!"); }  public void donegativeclick() {     // stuff here.     toast.maketext(actaudiorecords.this, getstring(r.string.the_operation_has_been_cancelled), toast.length_long).show();      log.i("fragmentalertdialog", "negative click!"); } 
  • i have no onresume() in code.
  • i tried use different codes dialogfragment doesn't matter.

it due line:

  actaudiorecords.this.oncreate(null); 

so after calling oncreate() null savedinstance have been removing link dialogfragment (as can understand), line refreshing activity, i solved problem splitting code in oncreate() should called once (at start of activity) , part should called in every refreshing point (such gui settings , etc).

i believe save current bundle , pass oncreate() instead of null , work now, thought calling function better data updating calling oncreate() on , over, that's it, thank wanted help.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -