我需要的是主要活动中的两个标签(固定)。在每个标签内部,我需要加载四个片段,按下第一个到第二个按钮,然后按第二个到第三个按钮,依此类推。这是否可能,如果是,我应该如何实现它?我使用minsdk作为8支持库。
目前我正在使用viewpager进行主要活动。它的代码如下
public class RegisterMainPage extends ActionBarActivity{
private ViewPager viewPager = null;
private ActionBar actionBar;
private PagerAdapter mPagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register_main_page);
//setting up an action bar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
viewPager = (ViewPager) findViewById(R.id.pager);
}
public class MyAdapter extends FragmentPagerAdapter{
public static final int PAGE_NUMS = 2;
public MyAdapter(FragmentManager fm){
super(fm);
// TODO Auto-generated constructor stub
}
@Override
public Fragment getItem(int arg0) {
// TODO Auto-generated method stub
Fragment fragment = null;
if(arg0 == 0){
fragment = new RegistrationIndividual();
}
if(arg0 == 1){
fragment = new RegistrationOrganizational();
}
return fragment;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return PAGE_NUMS;
}
@Override
public CharSequence getPageTitle(int position) {
// TODO Auto-generated method stub
if(position == 0){
return "Individual Member";
}
if(position == 1){
return "Organizational Member";
}
return null;
}
}
}
并且在xml中我有
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="htto://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:content=".MainActivity" >
<android.support.v4.view.PagerTabStrip
android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#16BDFF"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:textColor="#fff" />