标题视图

public class InfoFragment extends BaseFragment {
    private PullToRefreshListView ptrListView;
    private InfoAdapter adapter;

    private int page;
    private final int count = 10;
    private String bannnerUrl = "http://www.zhaoapi.cn/quarter/getAd";
    private String newsUrl = "http://172.17.8.100/movieApi/movie/v1/findHotMovieList?";
    /*@Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }*/

    @Override
    protected int getLayoutResId() {
        return R.layout.fragment_info;
    }

    @Override
    protected void initData() {
        requestNews();
        requetBanner();
    }

    @Override
    protected void initView(View view) {
        page = 1;
        ptrListView = view.findViewById(R.id.contents);
        adapter = new InfoAdapter(getActivity());
        ptrListView.setAdapter(adapter);
        ptrListView.setMode(PullToRefreshBase.Mode.BOTH);
        ptrListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
                page = 1;
                initData();
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
                requestNews();
            }
        });

    }


    private void requetBanner() {
        NetUtil.getInstance().getRequest3(bannnerUrl, BannerResponse.class, new NetUtil.NetCallback<BannerResponse>() {
            @Override
            public void onSuccess(BannerResponse o) {
                adapter.setBannerDatas(o.getData());
            }

            @Override
            public void onFail(String msg) {
                Toast.makeText(getActivity(), "请求Banner失败", Toast.LENGTH_SHORT).show();
            }
        });

    }

    private void requestNews() {

        NetUtil.getInstance().getRequest3(newsUrl + "page=" + page + "&count=" + count, NewsResponse.class, new NetUtil.NetCallback<NewsResponse>() {
            @Override
            public void onSuccess(NewsResponse o) {
                if (page == 1) {
                    adapter.setNewDatas(o.getResult());
                } else {
                    adapter.addNewDatas(o.getResult());
                }
                page++;
                ptrListView.onRefreshComplete();
                if (o.getResult().size() < count) {
                    ptrListView.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
                } else {
                    ptrListView.setMode(PullToRefreshBase.Mode.PULL_FROM_END);
                }
            }

            @Override
            public void onFail(String msg) {
                ptrListView.onRefreshComplete();
                Toast.makeText(getActivity(), "请求新闻失败", Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        adapter.stop();
    }
}
在这里插入代码片
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值