content: package com.example.y.mvp.fragment;
  
  import android.support.design.widget.TabLayout;
  import android.support.v4.view.ViewPager;
  
  import com.example.y.mvp.R;
  import com.example.y.mvp.adapter.TabNewsAdapter;
  import com.example.y.mvp.mvp.Bean.TabNewsInfo;
  import com.example.y.mvp.mvp.presenter.BasePresenter;
  import com.example.y.mvp.mvp.presenter.TabNewsPresenterImpl;
  import com.example.y.mvp.mvp.view.BaseView;
  import com.example.y.mvp.widget.MVPLazyFragment;
  
  import java.util.LinkedList;
  import java.util.List;
  
  import butterknife.Bind;
  
  /**
   * by 12406 on 2016/5/14.
   */
  public class NewsViewPagerFragment extends MVPLazyFragment implements BaseView.TabNewsView {
  
  
      @Bind(R.id.tab_layout)
      TabLayout tabLayout;
  
      @Bind(R.id.viewPager)
      ViewPager viewPager;
  
      private List<TabNewsInfo> data;
      private TabNewsAdapter tabNewsAdapter;
  
      public static NewsViewPagerFragment getInstance() {
          return new NewsViewPagerFragment();
      }
  
      @Override
      protected void initActivityCreated() {
  
          BasePresenter.TabNewsPresenter tabNewsPresenter = new TabNewsPresenterImpl(this);
          tabNewsPresenter.requestNetWork();
  
          data = new LinkedList<>();
          tabNewsAdapter = new TabNewsAdapter(getChildFragmentManager(), data);
      }
  
      @Override
      protected int getLayoutId() {
          return R.layout.fragment_viewpager;
      }
  
      @Override
      public void setData(List<TabNewsInfo> datas) {
          if (!datas.isEmpty()) {
              data.addAll(datas);
              viewPager.setAdapter(tabNewsAdapter);
              tabLayout.setupWithViewPager(viewPager);
          }
      }
  
      @Override
      public void netWorkError() {
          Toast(getString(R.string.network_error));
      }
  
  }
  