我正在使用片段活动,其中包含 5个标签(片段)..我需要的是第一个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中添加片段活动而不是片段? (顺便说一下,我跟着 http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/ 教程)
修改
tab1 => fragmentOne(onButtonClick替换)=> fragmentTwo(click)=> fragmentThree
tab2 => fragmentForth
tab3 => fragmentFifth
这就是我想要的
提前致谢
答案 0 :(得分:0)
以下是Fragments
示例Fragments Example中如何使用ActionBarSherlock's
标签的非常好的示例。看一看,我认为这是你想要实现的目标。 :)
答案 1 :(得分: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