package com.example.szx23; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.view.ViewPager; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import com.google.gson.Gson; import java.util.ArrayList; import java.util.List; public class Viewpagerap extends Fragment { private ListView l1; private ViewPager v1; private LinearLayout ll; private int e; private List<ImageView> imag_list = new ArrayList<>(); private List<String> tlist=new ArrayList<>(); private Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); e=v1.getCurrentItem(); v1.setCurrentItem(e+1); handler.sendEmptyMessageDelayed(1,3000); } }; private String lun="https://www.zhaoapi.cn/ad/getAd"; private String path="https://www.apiopen.top/novelApi"; public static Fragment getin(String s){ Viewpagerap viewpagerap=new Viewpagerap(); Bundle bundle=new Bundle(); bundle.putString("s",s); viewpagerap.setArguments(bundle); return viewpagerap; } @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { Bundle arguments = getArguments(); String string = arguments.getString("s"); if(string.equals("头条")) { View view=inflater.inflate(R.layout.toutiao,container,false); l1=view.findViewById(R.id.l1); ll=view.findViewById(R.id.ll); l1=view.findViewById(R.id.l1); v1=view.findViewById(R.id.v1); Uliter uliter=new Uliter(); uliter.getdata(lun); uliter.huidiao(new Uliter.Jiekou() { @Override public void getjson(String s) { Gson gson=new Gson(); LBean lBean = gson.fromJson(s, LBean.class); List<LBean.DataBean> data = lBean.getData(); for(int i=0;i<data.size();i++){ String icon = data.get(i).getIcon(); tlist.add(icon); } for(int w=0;w<tlist.size();w++){ //创建图片 ImageView imageView = new ImageView(getActivity()); //设置选择器 imageView.setImageResource(R.drawable.imageselector); ll.addView(imageView); imag_list.add(imageView); } imag_list.get(0).setSelected(true); Imagebase imagebase=new Imagebase(tlist,getActivity()); v1.setAdapter(imagebase); handler.sendEmptyMessageDelayed(1,3000); v1.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { for (int i = 0; i < imag_list.size(); i++) { if (i == position % imag_list.size()) { imag_list.get(i).setSelected(true); } else { imag_list.get(i).setSelected(false); } } } @Override public void onPageSelected(int position) { } @Override public void onPageScrollStateChanged(int state) { } }); } }); Uliter ii=new Uliter(); ii.getdata(path); ii.huidiao(new Uliter.Jiekou() { @Override public void getjson(String s) { Gson gson=new Gson(); Bean bean = gson.fromJson(s, Bean.class); List<Bean.DataBean> data1 = bean.getData(); Mybase mybase=new Mybase(data1,getActivity()); l1.setAdapter(mybase); } }); return view; } return null; } }
1234567898
最新推荐文章于 2024-08-13 23:16:50 发布