如何从片段更改操作栏选项卡

时间:2013-04-23 06:42:47

标签: android

我有3个操作栏标签回家:视频:默认购买将选择。我可以在不同的标签之间切换,我可以替换片段。我点击任何网格单元格中的主页片段中的gridview我使用下面的代码导航到购买标签,我可以用购买片段替换主页片段,但如何将操作栏选项卡从主页选项卡更改为购买标签?????

FragmentTransaction ft = parentActivity
                            .getFragmentManager()
                            .beginTransaction();
                    ft.replace(R.id.mainLayout,new purchase());
                    ft.commit();

class MyTabsListener implements ActionBar.TabListener {
        public Fragment fragment;

        public MyTabsListener(Fragment fragment) {
            this.fragment = fragment;
        }

        public void onTabReselected(Tab tab, FragmentTransaction ft) {
        }

        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            if (fragment != null) {
                ft.setCustomAnimations(R.animator.fragmentanimatorleft,
                        R.animator.fragmentanimatorright);
                ft.replace(R.id.mainLayout, fragment);
                // isSettingClicked = false;

            }

        }

        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            if (fragment != null) {
                try {
                    ft.remove(fragment);
                } catch (Exception e) {
                    // TODO: handle exception
                }
            }
        }

0 个答案:

没有答案