我有这个烦人的问题,我不知道如何解决。问题很简单:
我有FragmentA
哪个按钮点击FragmentB
(a ListView
)。在FragmentB
我可以FragmentA
用OnItemClick
. 所以你看,深度是无限的。
问题是当我FragmentB
第二次推送,然后返回(2 次)到第一个实例时,FragmentB
我在ListView
. 如果我要制作 10 个实例,那么我将在第一个实例中拥有所有 10 个实例的项目。
谁能解释这个问题并请给我一个解决方案?
编辑(代码片段):
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) {
// This can't be done immediately because the transaction may
// not
// yet be committed. Commits are are posted to the main
// thread's message loop.
mHandler.post(new Runnable() {
@SuppressLint("NewApi")
@Override
public void run() {
invalidateOptionsMenu();
}
});
}
}
}