android - Change Activities' Fragment Inside the Fragment -
i have activity, inside activity have fragment.
fragment have onclick method supposed to
change view.
want change view inside using onclick method inside the
fragment , use same activity.
so far can do.
fragment mfragment = null; class fragmentclass; fragmentclass = loginsignup.class; try { mfragment = (fragment) fragmentclass.newinstance(); } catch (exception me) { log.e(tag, me.tostring()); } fragmentmanager mfragmentmanager = getsupportfragmentmanager(); mfragmentmanager.begintransaction().replace(r.id.framelayout, mfragment).commit();
use below method
public static void openfragment(fragmentmanager manager, fragment targetfragment) { try { string fragmentname = targetfragment.getclass().getname(); manager.popbackstack(); manager.begintransaction() .replace(r.id.framelayout, targetfragment, fragmentname) .addtobackstack(fragmentname) .commit(); } catch (exception e) { e.printstacktrace(); } }
call method each time when opening fragment. have pass 2 params method. targetfragment fragment want open.
Comments
Post a Comment