发布替换片段

时间:2015-03-06 01:34:20

标签: android listview android-fragments android-listview

这是一个非常奇怪的问题。

我的应用程序包含一个主要活动,该活动是"路由器"对于我的应用程序中的所有片段这是我第一次在应用程序中集中使用片段。

我有一个包含许多链接的导航抽屉。其中一个链接包含一个带有BaseAdapter的ListView(Parent ListView),当用户点击该Parent ListView下的一个项目时,它会将用户带到另一个ListView(Child ListView)。当我尝试从Child ListView点击导航抽屉下的另一个链接时。应用程序首先加载Parent ListView,然后将用户带到他们单击的位置。

我的想法是我从Parent ListView移动到Child ListView,我没有正确附加下一个片段(Child ListView)。下面是Parent的ListView BaseAdapter中的代码,该代码将用户从Parent发送到Child ListView。

            Fragment newFragment = new SingleCartListView();
            FragmentTransaction transaction = ((FragmentActivity)context).getSupportFragmentManager().beginTransaction();

            Bundle bundle = new Bundle();
            bundle.putString("def_cart_id", resultp.get(ViewCartsFragment.DEFCARTID));
            bundle.putString("cart_name", resultp.get(ViewCartsFragment.CARTNAME));
            newFragment.setArguments(bundle);

            transaction.replace(R.id.frame_container, newFragment);
            transaction.addToBackStack(null);

            transaction.commit();

非常感谢任何帮助。

感谢。

1 个答案:

答案 0 :(得分:0)

MainActivity:单击NavDrawer中的项目时,从堆栈中删除所有片段,然后调用片段事务。执行以下操作:

FragmentManager manager = getSupportFragmentManager();
manager.popBackStack();

// now change the fragment
manager.beginTransaction().replace((R.id.frame_container, newFragment);
transaction.addToBackStack(null);

transaction.commit();
相关问题