PullListView 和侧滑 如何正确结合运用.....

<布局>

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activity.ShowActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.handmark.pulltorefresh.library.PullToRefreshListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/pull_list"></com.handmark.pulltorefresh.library.PullToRefreshListView>
    </LinearLayout>

    <!--侧滑-->
    <RelativeLayout
        android:layout_width="320dp"
        android:layout_gravity="start"
        android:layout_height="match_parent"
        android:background="@color/colorPrimary"></RelativeLayout>

</android.support.v4.widget.DrawerLayout>

 

<主界面>

public class ShowActivity extends BaseActivity implements NetCallback, AdapterView.OnItemClickListener {

    private PullToRefreshListView pullListView;
    //接口
    private String api = "http://172.17.8.100/mobile/exam/findNewList";
    private boolean isPull = false;
    private MainAdapter adapter;
    //定义数据集
    private List<MainBean.ResultBean.DataBean> dataBeanList = new ArrayList<>();

    @Override
    protected void findView() {
       pullListView = findViewById(R.id.pull_list);
    }

    @Override
    protected void setListener() {
        pullListView.setOnItemClickListener(this);

    }

    @Override
    protected void initFinish() {
        //设置支持上拉下拉
        pullListView.setMode(PullToRefreshBase.Mode.BOTH);
        //设置监听
        pullListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> pullToRefreshBase) {
                isPull = true;
                loadData();
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> pullToRefreshBase) {
                loadData();
            }
        });
        //设置适配器
        adapter = new MainAdapter(this,dataBeanList);
        pullListView.setAdapter(adapter);
        loadData();
    }

    //加载数据
    private void loadData() {
        utils.getDataFromService(api,this);
    }

    @Override
    protected int initLayout() {
        return R.layout.activity_show;
    }

    @Override
    public void onSuccess(String result) {
        //解析数据
        Gson gson = new Gson();
        MainBean mainBean = gson.fromJson(result,MainBean.class);

        //下拉
        if (isPull){
            isPull =! isPull;
            dataBeanList.clear();
        }
        //添加数据
        dataBeanList.addAll(mainBean.getResult().getData());

        //更新数据
        adapter.notifyDataSetChanged();

        //停止刷新
        pullListView.onRefreshComplete();
    }

    @Override
    public void onError(String errorMsg) {

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent intent = new Intent(this,DataActivity.class);
        MainBean.ResultBean.DataBean item = adapter.getItem(position);
        intent.putExtra("url",item.getUrl());
        startActivity(intent);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值