此方法切换的只是图片用的是简单的handler,并不是自动轮播图片
布局:
<ImageView android:id="@+id/faxian_img" android:layout_width="match_parent" android:layout_height="200dp" />
=====================代码===========================
public class FragmentFaxin extends Fragment{ private PullToRefreshScrollView refreshScrollView; private ImageView imageView; private GridView gridView; List<String> list=new ArrayList<>(); private int index=0; Handler handler=new Handler(){ @Override public void handleMessage(Message msg) {//接到消息,显示图片 if (msg.what==0){ index++; ImageLoader.getInstance().displayImage(list.get(index%list.size()),imageView, ImageUtil.getoption()); handler.sendEmptyMessageDelayed(0,3000); } } }; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_faxian, container, false); imageView = (ImageView) view.findViewById(R.id.faxian_img); return view; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); String path="xxxxxxxxxxxxx"; NetConnection.getconnection(getActivity(), path, new CallJsonBack() { @Override public void getcallBack(String json) { if (json!=null){ Gson gson=new Gson(); ImageBean imageBean = gson.fromJson(json, ImageBean.class); List<ImageBean.ResultBean.DataBean.StepsBean> steps = imageBean.getResult().getData().get(0).getSteps(); for (ImageBean.ResultBean.DataBean.StepsBean stepsBean: steps) { list.add(stepsBean.getImg()); }//现在图片集合有数据,,,,展示图片,,,展示第一张图片 ImageLoader.getInstance().displayImage(list.get(0),imageView, ImageUtil.getoption()); handler.sendEmptyMessageDelayed(0,3000); } } }); } }