标签:
public class MainActivity extends FragmentActivity {
private ViewPager vp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vp = (ViewPager) findViewById(R.id.vp);
vp.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public int getCount() {
// TODO Auto-generated method stub
return 2;
}
@Override
public Fragment getItem(int arg0) {
// TODO Auto-generated method stub
Fragment fragment=null;
switch (arg0) {
case 0:
fragment=new Fragment1();
break;
case 1:
fragment=new Fragment2();
break;
default:
break;
}
return fragment;
}
});
}
-------------
public class Fragment1 extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view = inflater.inflate(R.layout.layou_fragment1, null);
return view;
}
}
标签:
原文地址:http://www.cnblogs.com/fanzhiguo/p/5789811.html