android - refresh fragment that gone to activity after back pressed in that activity -
i have fragment in tabbed activity.it redirects onclicklistener activity.after changes made in activity.user press button.so in fragment need listener fired after come activity.or maybe after user made changes give user button go fragment , reload fragment meanwhile.i don't know either way. tried onresume() onstart() on every thing didn't work because nothing happened fragment in transaction. tried addonbackstackchangedlistener() should placed in activity not fragment. don't know do? time
public static class placeholderfragment extends fragment { /** * fragment argument representing section number * fragment. */ private static final string arg_section_number = "section_number"; /** * returns new instance of fragment given section * number. */ public static placeholderfragment newinstance(int sectionnumber) { placeholderfragment fragment = new placeholderfragment(); bundle args = new bundle(); args.putint(arg_section_number, sectionnumber); fragment.setarguments(args); return fragment; } public placeholderfragment() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, final bundle savedinstancestate) { final view rootview = inflater.inflate(r.layout.fragment_history, container, false); getfragmentmanager().addonbackstackchangedlistener( new fragmentmanager.onbackstackchangedlistener() { @override public void onbackstackchanged() { getfragmentmanager().begintransaction().detach(gettargetfragment()).attach(gettargetfragment()).commit(); } }); //textview textview = (textview) rootview.findviewbyid(r.id.section_label); //textview.settext(getstring(r.string.section_format, getarguments().getint(arg_section_number))); return rootview; } @override public void onstart() { super.onresume(); getfragmentmanager().begintransaction().detach(this).attach(this).commit(); } public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); getfragmentmanager().begintransaction().detach(this).attach(this).commit(); }
let's have 2 two activities , b.initially fragment f1 added a.when click on item in f1 start activity b startactivityforresult (intent intent, int requestcode) , in onactivityresult(int requestcode, int resultcode, intent data) either update fragment data(if possible) or reload fragment.
Comments
Post a Comment