1

我正在使用具有5 个选项卡(片段)的 fragmentactivity.. 我需要的是第一个 tab1 有Enter按钮并单击它将切换到 tab1 中的另一个片段而不会得到任何奇怪的结果,就像现在这就是我正在做的在 onClickListener

FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.detach(Frag_Home.this);
ft.commit();                    
Frag_Locations newFragment = new Frag_Locations();
FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();


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

transaction.commit();
getActivity().getSupportFragmentManager().executePendingTransactions();

**上面的代码改变了内容,但新添加的片段覆盖了整个视图,新打开的片段浮动在选项卡上方!

如何在tab1而不是fragment中添加fragmentactivity?(顺便说一句,我跟着http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/教程)

编辑

tab1 => fragmentOne (onButtonClick 替换) => fragmentTwo (click) =>fragmentThree

tab2 => fragmentForth

tab3 => fragmentFifth

这就是我要的

提前致谢

4

2 回答 2

0

Fragments这是一个非常好的示例,说明如何在示例中使用选项卡ActionBarSherlock's片段示例。看一看,我认为这是您想要实现的目标。:)

于 2013-02-16T16:11:17.107 回答
0

我就是这样收场的。。

人们可能知道在选项卡中添加片段

// HashMap for storing fragments so we could track them by their names
private HashMap mapTabInfo = new HashMap();

  // This one is the normal way to add fragment to tab (mine is customized so better look into some nice tutorial for better understading)
tabview = createTabView(mTabHost.getContext(), MY_TICKET, R.drawable.tab_icon_myticket_selector);
            MainTabActivity.addTab(this, this.mTabHost,
            this.mTabHost.newTabSpec(MY_TICKET).setIndicator(tabview),
            (tabInfo = new TabInfo(MY_TICKET, Frag_MyTicket.class, args)));

    this.mapTabInfo.put(tabInfo.tag, tabInfo);

    // Add these fragments here so we can track them by own interface's method 
    tabInfo = new TabInfo(LOCATIONS, Frag_Locations.class, args);
    this.mapTabInfo.put(LOCATIONS, tabInfo);

// These two fragments won't show up in tabs untill we make it display manually 
    tabInfo = new TabInfo(DAYS, Frag_Days.class, args);
    this.mapTabInfo.put(DAYS, tabInfo);

// Now when we want to show fragment LOCATION while showing My_TICKET fragment, we'll just call method
onTabChanged(String tag) // method called when tabs are tapped, call this method with string LOCATIONS and you are done there..

// I know this might not be easiest to understand, you'll understand the logic if you're familiar with fragments/tabs
于 2013-06-08T19:23:03.640 回答