MainActivity.java
public class MainActivity extends FragmentActivity {
// Fragment TabHost as mTabHost
private FragmentTabHost mTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Tab1"),
Tab1Fragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("Tab2"),
Tab2Fragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("Tab3"),
Tab3Fragment.class, null);
}
}
Tab1Fragment.java
public class Tab1Fragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View V = inflater.inflate(R.layout.tab1_view, container, false);
return V;
}
}
Tab2Fragment.java
public class Tab2Fragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View V = inflater.inflate(R.layout.tab2_view, container, false);
return V;
}
}
Tab3Fragment.java
public class Tab3Fragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View V = inflater.inflate(R.layout.tab3_view, container, false);
return V;
}
}
activity_main.xml中
android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
我的输出 ::
tab 1
----&gt; Activity 1
应该显示。tab 1
(再次)------&gt; Activity 2
应该显示。tab 1
(再次)第三次 ----&gt; Activity
1
应显示again
。翻转FLOP NATURE的种类
任何iDeas
答案 0 :(得分:1)
你必须保持你的标签点击,当你点击标签时,你必须管理一个点击增量的计数器,当你点击标签时,你将根据点击计数器检查这个条件......
答案 1 :(得分:1)
哦,我将逐步解释这一点 1.只需要像singlton类那样上课,或者你应该在任何一个类中使用一个静态int计数器。 2.当你单击选项卡然后在选项卡clicklistner上时,首先你检查计数器的值是什么,如果计数器== 1然后第一次活动调用 如果计数器== 2则第二次活动呼叫 counter == 3然后是第三次活动电话
最后只需增加你的计数器,如果计数器> 3,则计数器= 1;
计数器是静态的,所以在app的整个执行中它将是恒定的并且相同:)