package com.example.rk_02;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private List<Fragment> list;
private MyApp myApp;
private ViewPager viewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager = (ViewPager) findViewById(R.id.vp);
list = new ArrayList<>();
list.add(new AlankFragment());
list.add(new BlankFragment());
list.add(new ClankFragment());
myApp = new MyApp(getSupportFragmentManager());
viewPager.setAdapter(myApp);
}
class MyApp extends FragmentPagerAdapter {
public MyApp(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return list.get(position);
}
@Override
public int getCount() {
return list.size();
}
}
}
viewpapger+fragment
最新推荐文章于 2022-04-08 20:36:29 发布