大家好我有一个ViewPager我想要一个设置活动,但是我不能这样做,因为它是一个Activity而不是一个片段,我能做到吗?
我想要这样的事情:
http://tjerktech.files.wordpress.com/2012/06/spotify1.png
我有一些代码:
PagerAdapter mSectionsPagerAdapter;
List<Fragment> fragments = new Vector<Fragment>();
/**
* The {@link ViewPager} that will host the section contents.
*/
ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_days_routine);
// Set up the action bar.
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
//String nameRoutine = getIntent().getExtras().getString("nameRoutine");
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
for(int i= 0;i<5;i++){
fragments.add(Fragment.instantiate(this, Activity.class.getName()));
}
mSectionsPagerAdapter = new PagerAdapter(this.getSupportFragmentManager(), fragments);
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
// When swiping between different sections, select the corresponding
// tab. We can also use ActionBar.Tab#select() to do this if we have
// a reference to the Tab.
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
// For each of the sections in the app, add a tab to the action bar.
for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
// Create a tab with text corresponding to the page title defined by
// the adapter. Also specify this Activity object, which implements
// the TabListener interface, as the callback (listener) for when
// this tab is selected.
actionBar.addTab(
actionBar.newTab()
.setText(getResources().getString(R.string.tab_day) + " " +(i+1))
.setTabListener(this));
}
}