tablayout动态添加服务器请求的数据

compile 'com.android.support:design:26+'
compile 'com.squareup.okhttp3:okhttp:3.4.2'
//xrecyclerview的依赖上下拉刷新
implementation 'com.jcodecraeer:xrecyclerview:1.5.9'
//图片加载框架glide
compile 'com.github.bumptech.glide:glide:3.7.0'

 


    

    


 

 

public class MainActivity extends AppCompatActivity {
    private TabLayout tabLayout;
    private ViewPager viewPage;
    private List frags;
    private List titles =new ArrayList<>();
    private Fragment[] f;
    private String path_shop="http://nxf.dykj168.com/index.php?s=/Home/study/studySonCategory&id=12";
    private Myadapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //获取资源id
        viewPage= (ViewPager) findViewById(R.id.viewPage);
        tabLayout= (TabLayout) findViewById(R.id.tabLayout);
      //网络请求
        initData();
//创建fragment集合
        frags=new ArrayList<>();
        frags.add(new Fragment1());
        //动态请求的数据集合
        titles=new ArrayList<>();

        tabLayout.setupWithViewPager(viewPage);
        adapter = new Myadapter(getSupportFragmentManager());
        viewPage.setOffscreenPageLimit( titles.size() );
        //联动
        viewPage.setAdapter(adapter);
        adapter.notifyDataSetChanged();
    }
    private void initData() {
       OkhttpUtils getshu = OkhttpUtils.getshu();
        getshu.say(path_shop, new OkhttpUtils.fun1() {



            @Override
            public void onres(String string) {
                Gson gson = new Gson();
                    Story_Bean story_bean = gson.fromJson(string, Story_Bean.class);
                List   data = story_bean.getData();
                //for循环便利数据展示
                for (int i = 0; i  
  

 

 

你可能感兴趣的:(tablayout动态添加服务器请求的数据)