package com.bwei.fragment;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.bwei.adapter.MyAdapter;
import com.bwei.day14_lianxi5.R;
import java.util.ArrayList;
/**
* Created by 杨柳 on 2018/7/19.
*/
public class Fragment1 extends Fragment{
private TabLayout tab_layout;
private ViewPager view_pager;
private ArrayList<Fragment> fragments;
private MyAdapter myAdapter;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View inflate = inflater.inflate(R.layout.fragemnt1_layout, container, false);
tab_layout = inflate.findViewById(R.id.tab_layout);
view_pager = inflate.findViewById(R.id.view_pager);
return inflate;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
fragments = new ArrayList<>();
fragments.add(new Fragment11());
fragments.add(new Fragment12());
fragments.add(new Fragment13());
myAdapter = new MyAdapter(getChildFragmentManager(), fragments);
view_pager.setAdapter(myAdapter);
}
}