android - what is correct approach to perform UI related task when a dialog gets dismissed -


i have dialog ondismiss handler:

public class textreaderdialog extends dialogfragment {     ...      public void ondismiss() {      } 

i show dialog , add styles part of text fragment:

textreaderdialog d = new textreaderdialog(); d.show(getfragmentmanager(), "sample");  spannable spannabletext = new spannablestring(tv.gettext()); spannabletext.setspan(new backgroundcolorspan(color.ltgray), startoffset, startoffset + w.word.length(), spannable.span_exclusive_exclusive); tv.settext(spannabletext); 

whenever dialog dismissed, want remove styles text. how can that? correct way that?

the simplest way go add method fragment so:

public void dismissstyles(){     //do style dismissing here } 

now, assume in dialog overriding dialogfragment.ondismiss(dialoginterface dialog). long case, once have completed method, in dialog's ondismiss function, can effect of:

@override public void ondismiss(dialoginterface dialog) {     super.ondismiss(dialog);     myfragment fragment = (myfragment) activity          .getfragmentmanager()          .findfragmentbyid(r.id.containerofyourfragment);     if(fragment != null){          fragment.dismissstyles();     } } 

here, activity should current activity fragment , dialog hosted in. can pass dialog in constructor, or depending on dialog located. pass current fragment dialog in constructor well, , called myfragment.dismissstyles();.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -