android - Using fragment more than one time with new values with backstack maintain -
i making app using sliding menu , tab in bottom...whole app fragment based..i facing problem using fragment a click on button , go fragment b,in fragment b there button on clicking on button fragment a update new values..and on
means switching a->b should occur..but backstack should mantain..
here code backstack:
public static void gotofragmentwithbackstack(fragment fragment) { fragment tmp = fm.findfragmentbytag(fragment.getclass().getname()); if (tmp != null && tmp.isvisible()) return; ft = fm.begintransaction(); ft.add(r.id.content_frame, fragment, fragment.getclass().getname()); ft.settransition(fragmenttransaction.transit_fragment_open); ft.addtobackstack(null); ft.commit(); currenttag = fragment.getclass().getname(); }
here using method go next fragment. , button mantained activity's backpressed. when use method , again call fragment a(which in container) not called...and if use gotofragment method called old fragment destroyed(blank screen occur).here gotofragment method:
public static void gotofragment(fragment fragment) { fragment tmp = fm.findfragmentbytag(fragment.getclass().getname()); if (tmp != null && tmp.isvisible()) return; ft = fm.begintransaction(); ft.replace(r.id.content_frame, fragment); ft.settransition(fragmenttransaction.transit_fragment_open); ft.commit(); currenttag = fragment.getclass().getname(); log.d("trong", "backpressedcurrenttag " + currenttag); }
i have used concept reused used fragment : android - instantiate fragment multiple times
but not helped.let me clear problem again:
i want use used fragment again , again in container , fragments should call on pressed
the flow should : a->b->a->b->a , on backpressed: a<-b<-a<-b<-a (every time have new values ,new data)
please me.thanks in advance.
the new instances of fragment ..i have made this:
public static followerfragment newinstance() { return new followerfragment(null,null,null); } public static fragment newinstance(string cat_id,string status,string id) { return new followerfragment(cat_id,status,id); } public followerfragment(string cat_id,string status,string id) { // todo auto-generated constructor stub this.str_status=cat_id; this.counter = status; this.user_id = id; }
this extended comment better op understand needs done.
ok, have fragmenta
, fragmentb
.
within fragmenta
replace container new fragmentb
.
fragmentb
want display fragmenta
again, new data, you're wanting keep original fragment old data in backstack. doesn't work that.
the following simplified example of direction should going achieve goal.
since you're wanting display different information on each fragment, constructor each fragment should include way tell should displayed, example:
public class fragmenta{ string mtext; public fragmenta(string text){ mtext = text; } }
now, when need create new fragmenta
within fragmentb
or wherever, need such as, , using own methods:
gotofragmentwithbackstack(new fragmenta("this new data"));
again, basic example of should doing, instead of recycling old fragments new data. can't copy/paste , expect work, gives idea of you'll need do.
Comments
Post a Comment