多层json解析对象封装

public class MainActivity extends BaseActivity {

private PullToRefreshListView listView;
private GridView gridView;
private Banner banner;
private String bannerUrl = "https://api.apiopen.top/musicRankings?tdsourcetag=s_pcqq_aiomsg";
private String listviewUrl = "http://172.17.8.100/small/commodity/v1/commodityList";

@Override
public int bindLayout() {
    return R.layout.activity_main;
}

@Override
protected void initView() {
    banner = bindView(R.id.banner);
    gridView = bindView(R.id.gv);
    listView = bindView(R.id.pull);
    listView.setMode(PullToRefreshBase.Mode.BOTH);
    listView.setPullToRefreshOverScrollEnabled(true);
    listView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2() {
        @Override
        public void onPullDownToRefresh(PullToRefreshBase refreshView) {
            //请求网络
            //刷新控件
            listView.onRefreshComplete();
        }

        @Override
        public void onPullUpToRefresh(PullToRefreshBase refreshView) {
            //请求网络
            //把集合2的数据给集合1
            //刷新适配器
            //刷新控件
            listView.onRefreshComplete();
        }
    });

}

@Override
protected void initData() {
    //轮播图
    HttpUtils.httpAsynTask(bannerUrl, new HttpUtils.CallBackString() {
        @Override
        public void getData(String s) {
            Gson gson = new Gson();
            JsonBean bean = gson.fromJson(s, JsonBean.class);
            ArrayList result = bean.getResult();
            banner.setImages(result);
            banner.setImageLoader(new ImageLoader() {
                @Override
                public void displayImage(Context context, Object path, ImageView imageView) {
                    Two two = (Two) path;
                    Glide.with(MainActivity.this).load(two.getPic_s192()).into(imageView);
                }
            });
            banner.isAutoPlay(true);//是否轮播true是
            banner.setDelayTime(3000);//图片切换时间
            banner.start();//开始轮播
        }
    });
    //列表
    HttpUtils.httpAsynTask(listviewUrl, new HttpUtils.CallBackString() {
        @Override
        public void getData(String s) {
            Gson gson = new Gson();
            JsonBean2 bean = gson.fromJson(s, JsonBean2.class);
            JsonBean2.ResultBean result = bean.getResult();
            JsonBean2.ResultBean.MlssBean mlss = result.getMlss();
            JsonBean2.ResultBean.PzshBean pzsh = result.getPzsh();
            JsonBean2.ResultBean.RxxpBean rxxp = result.getRxxp();

            ArrayList list = new ArrayList<>();

            list.addAll(mlss.getCommodityList());
            list.addAll(pzsh.getCommodityList());
            list.addAll(rxxp.getCommodityList());
            LGAdapter adapter = new LGAdapter(MainActivity.this, list);
            listView.setAdapter(adapter);
            //gridview
            gridView.setAdapter(adapter);

        }
    });


}

@Override
protected void bindEvent() {

}

}

你可能感兴趣的:(多层json解析对象封装)