android - Is it recommended to call onDetach() & onAttach() method of the FragmentTransaction manually -


i want change font size of entire application. have used 3 styles(small, medium,large), keeping app theme parent. whenever user selects the font change button, based on selected style, i'm changing font size of entire application. since, fragment, theme has applied inside oncreateview(), before inflating layout,theme not applied fragment on click of font size change button. need refresh fragment, it's view recreated. i'm manually detaching fragment , attaching again activity. destroys fragment view , recreates , fragment ui updated. query is, recomended call ondetach() & onattach() manually? how i'm refreshing fragment:

private void reloadfragment() {         android.support.v4.app.fragmentmanager mngr = getsupportfragmentmanager();         fragment fragment = mngr.findfragmentbyid(r.id.container);         if (fragment instanceof homefragment) {             try {                 sectionpageradapter adapter = ((homefragment) fragment).getadapter();                 android.support.v4.app.fragmenttransaction transaction = this.getsupportfragmentmanager().begintransaction();                 transaction.detach(fragment).commitallowingstateloss();                 transaction.attach(fragment);                 adapter.notifydatasetchanged();//i'm using viewpager, notifying             } catch (illegalstateexception e) {                 e.printstacktrace();             }         }       } 

thanks in advance..

no, can this. life circle methods can't called manually. if want change fragments, need this:

private void reloadfragment() {     android.support.v4.app.fragmentmanager mngr = getsupportfragmentmanager();     fragment fragment = mngr.findfragmentbytag(tag);     if (fragment == null){         fragment = new yourfragment();     }     if (fragment instanceof homefragment) {         try {             sectionpageradapter adapter = ((homefragment) fragment).getadapter();             android.support.v4.app.fragmenttransaction transaction = this.getsupportfragmentmanager().begintransaction();             transaction.replace(resid, fragment, tag);             adapter.notifydatasetchanged();//i'm using viewpager, notifying         } catch (illegalstateexception e) {             e.printstacktrace();         }     } } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -