我有一个包含5个不同片段的活动,您可以轻扫。我想知道如何在5个不同的活动类中刷卡。
以下是滑动片段的代码:
public class MainActivity extends FragmentActivity {
private PageAdapter mPagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.viewpager_layout);
initialisePaging();
}
private void initialisePaging() {
// TODO Auto-generated method stub
List<Fragment> fragments = new Vector<Fragment>();
fragments.add(Fragment.instantiate(this, Fragment1.class.getName()));
fragments.add(Fragment.instantiate(this, Fragment2.class.getName()));
fragments.add(Fragment.instantiate(this, Fragment3.class.getName()));
fragments.add(Fragment.instantiate(this, Fragment4.class.getName()));
fragments.add(Fragment.instantiate(this, Fragment5.class.getName()));
mPagerAdapter = new PageAdapter(this.getSupportFragmentManager(), fragments);
ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
pager.setAdapter(mPagerAdapter);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
onBackPressed();
}
return super.onKeyDown(keyCode, event);
}
@Override
public void onBackPressed() {
Log.d("CDA", "onBackPressed Called");
Intent intent = new Intent(this, MoodActivity.class);
startActivity(intent);
}