Xlistview的条目展示和上拉加载下拉刷新

public class OneFragment extends Fragment implements XView,XListView.IXListViewListener {

private String mUrl = "http://api.expoon.com/AppNews/getNewsList/type/1/p/";
private XListView xListView;
private int index = 1;

private List<Data.PostsBean> lists = new ArrayList<>();
private XPresenterImpl presenter;
private MyAdapter adapter;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_one, container, false);
    initView(view);
    //实例化
    presenter=new XPresenterImpl(this);

    xListView.setXListViewListener(this);
    xListView.setPullLoadEnable(true);

    adapter = new MyAdapter(lists,getActivity());
    xListView.setAdapter(adapter);

    presenter.startRequest(mUrl,index);

    return view;
}

private void initView(View view) {
    xListView = view.findViewById(R.id.xlist2);
}

@Override
public void onRefresh() {
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            lists.clear();
            index=1;
            presenter.startRequest(mUrl,index);
        }
    },1000);
}

@Override
public void onLoadMore() {
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            index++;
            presenter.startRequest(mUrl,index);
        }
    },1000);
}

@Override
public void success(List<Data.PostsBean> data) {
    lists.addAll(data);
    adapter.notifyDataSetChanged();
    stop();
}
private void stop() {
    xListView.stopLoadMore();
    xListView.stopRefresh();
    xListView.setRefreshTime("刚刚");
}

@Override
public void error(String error) {
    Toast.makeText(getActivity(), error, Toast.LENGTH_SHORT).show();
}

}

布局

<com.example.daylibrary.maxwin.maxwin.maxwin.view.XListView
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:id="@+id/xlist2"/>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值