android - Fragment issue (Multiple instances) -
i have annoying problem don't know how solve. problem straightforward:
i have fragmenta
pushes fragmentb
(a listview
) on button click. in fragmentb
can push fragmenta
onitemclick
. see, depth infinite.
the problem when pushed fragmentb
second time, , go (2 times) first instance of fragmentb
have items first , second instance in listview
. if make 10 instances, have items of 10 instances in first instance.
can explain problem , please provide me solution?
edit (code snippet):
followersfragment frag = new followersfragment(); bundle bundle = new bundle(); bundle.putstring(constants.user_id, userid); frag.setarguments(bundle); ((mainactivity) getactivity()).pushfragment(frag); public void pushfragment(trigdfragment fragment) { pushfragment(fragment, new animationobject()); } public void pushfragment(trigdfragment fragment, animationobject animate) { switchcontent(fragment, animate, false); } public void switchcontent(trigdfragment fragment, animationobject anim, boolean clearbackstack) { actionbarhelper mactionbarhelper = actionbarhelper.getinstance(); supportinvalidateoptionsmenu(); fragmentmanager mgr = getsupportfragmentmanager(); if (clearbackstack) { mactionbarhelper.setdisplayhomeasdrawerenabled(true); mgr.popbackstack(null, fragmentmanager.pop_back_stack_inclusive); } else { mactionbarhelper.setdisplayhomeasupenabled(true); } fragment.setupactionbar(getresources()); fragmenttransaction ft = mgr.begintransaction(); boolean doinganimation = false; if (util.hasicecreamsandwich()) { doinganimation = anim != null; if (doinganimation) { ft.setcustomanimations(anim.enterresource, anim.exitresource, anim.popenterresource, anim.popexitresource); } } ft.replace(r.id.content_frame, fragment, "current"); if (!clearbackstack) { ft.addtobackstack(null); } ft.commitallowingstateloss(); if (util.hasicecreamsandwich()) { if (doinganimation) { // can't done because transaction may // not // yet committed. commits are posted main // thread's message loop. mhandler.post(new runnable() { @suppresslint("newapi") @override public void run() { invalidateoptionsmenu(); } }); } } }
instead of creating new instance of fragments can use replace
function of fragmenttransaction
transaction.replace(r.id.fragment_container, newfragment);
Comments
Post a Comment