findFragmentByTag()即使我知道它存在,也找不到我的片段

时间:2014-04-23 15:41:31

标签: android android-fragments

我写下这个条件:

 if(activity.getSupportFragmentManager().getBackStackEntryCount()!=0 &&
 activity.getSupportFragmentManager().findFragmentByTag("detail") != null && compteur==0){

我知道应用程序应该进入这个条件背后的块,因为我使用了Eclipse的调试工具,我浏览变量以在我的活动中找到我的backStack,并且包含BackStack片段的Array显示:

 [BackStackEntry{53954aa4 #0 detail}, null, null, null, null, null, null, null, null, null, null, null]

所以我的应用程序应该进入块但不是......而且我设置了所有我可以做的,以便在应用程序验证其内容时验证数组的状态:它确切地说是状态我在上面写了

findFragmentByTag()是否完全符合我们对此函数名称的看法?或者它做了一些与我无法想象的不同的事情?

编辑:

上面数组中的片段来自此代码:

FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.layOffers, newOffer, "detail");
transaction.addToBackStack("detail");
transaction.commit();

尝试使用此功能不会改变任何内容:

FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.layOffers, newOffer, "detail");
transaction.addToBackStack("detail");
transaction.commit();

1 个答案:

答案 0 :(得分:0)

在您的代码中,您还没有在替换方法中提到标记所以, 使用片段

的替换方法的这种结构
replace(int containerViewId, Fragment fragment, String tag)

ft.replace(R.id.container, newFragment,"detail");
相关问题