public class Fragment1 extends Fragment{
private List data = new ArrayList<>();
private TabLayout mytab;
private ViewPager viewPager;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment1, container, false);
mytab = view.findViewById(R.id.MtTab);
viewPager = view.findViewById(R.id.viewpager);
data.add(new ShuJu("新闻","http://www.93.gov.cn/93app/data.do?channelId=2&startNum=1"));
data.add(new ShuJu("北京","http://www.93.gov.cn/93app/data.do?channelId=2&startNum=2"));
data.add(new ShuJu("南京","http://www.93.gov.cn/93app/data.do?channelId=2&startNum=3"));
data.add(new ShuJu("深圳","http://www.93.gov.cn/93app/data.do?channelId=2&startNum=4"));
data.add(new ShuJu("广州","http://www.93.gov.cn/93app/data.do?channelId=2&startNum=5"));
data.add(new ShuJu("杭州","http://www.93.gov.cn/93app/data.do?channelId=2&startNum=6"));
data.add(new ShuJu("娱乐","http://www.93.gov.cn/93app/data.do?channelId=2&startNum=7"));
data.add(new ShuJu("小事","http://www.93.gov.cn/93app/data.do?channelId=2&startNum=8"));
data.add(new ShuJu("大事","http://www.93.gov.cn/93app/data.do?channelId=2&startNum=9"));
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
viewPager.setAdapter(new Myadapter(getActivity().getSupportFragmentManager()));
mytab.setupWithViewPager(viewPager);
}
//viewpager 与 TabLayout的适配器
class Myadapter extends FragmentPagerAdapter{
public Myadapter(FragmentManager fm) {
super(fm);
}
@Override
public CharSequence getPageTitle(int position) {
return data.get(position).getNaem();
}
@Override
public Fragment getItem(int position) {
Zi_Fragment zi_fragment = new Zi_Fragment();
//传递参数
Bundle bundle=new Bundle();//key:string vavle:object
bundle.putString("url",data.get(position).getUrl());
zi_fragment.setArguments(bundle);
return zi_fragment;
}
@Override
public int getCount() {
return data.size();
}
}
}
public class Zi_Fragment extends Fragment{
private String url;
private PullToRefreshListView plistview;
private List