Xrecyclerview的使用(上拉刷新,下拉加载)

1.导入依赖

compile 'com.jcodecraeer:xrecyclerview:1.3.2'

2,权限配置

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>

3,activity_main中的使用

<com.jcodecraeer.xrecyclerview.XRecyclerView
    android:layout_width="match_parent"
    android:id="@+id/xre_xrv"
    android:layout_height="match_parent">

</com.jcodecraeer.xrecyclerview.XRecyclerView>

4。mainActivity中的使用

package com.bwie.xrecyclerview_lianxi;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    String mpath="http://result.eolinker.com/umIPmfS6c83237d9c70c7c9510c9b0f97171a308d13b611?uri=homepage";
    XRecyclerView xrv_xrv;
//    private RecyclerView mRecyclerView;
    private List<String> mDatas;
    private HomeAdapter mAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        xrv_xrv = (XRecyclerView) findViewById(R.id.xre_xrv);
        initData();
        xrv_xrv.setLayoutManager(new LinearLayoutManager(this));
        xrv_xrv.addItemDecoration(new DividerItemDecoration(this,
                DividerItemDecoration.VERTICAL_LIST));
        xrv_xrv.setAdapter(mAdapter = new HomeAdapter());
        xrv_xrv.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                Toast.makeText(MainActivity.this,"加载页面",Toast.LENGTH_LONG).show();
                xrv_xrv.refreshComplete();
            }

            @Override
            public void onLoadMore() {
             mDatas.add("下拉加载");
             mDatas.add("下拉加载");
             mDatas.add("下拉加载");
             mDatas.add("下拉加载");
             mDatas.add("下拉加载");
             mDatas.add("下拉加载");
             mDatas.add("下拉加载");
             mDatas.add("下拉加载");
             mDatas.add("下拉加载");
             mDatas.add("下拉加载");
             mDatas.add("下拉加载");
             mDatas.add("下拉加载");
             mDatas.add("下拉加载");
                xrv_xrv.loadMoreComplete();
            }
        });
    }
    protected void initData()
    {
        mDatas = new ArrayList<String>();
        for (int i = 'A'; i < 'z'; i++)
        {
            mDatas.add("" + (char) i);
        }
    }
    class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.MyViewHolder>
    {

        @Override
        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
        {
            MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
                    MainActivity.this).inflate(R.layout.item_home, parent,
                    false));
            return holder;
        }

        @Override
        public void onBindViewHolder(MyViewHolder holder, int position)
        {
            holder.tv.setText(mDatas.get(position));
        }

        @Override
        public int getItemCount()
        {
            return mDatas.size();
        }

        class MyViewHolder extends RecyclerView.ViewHolder
        {

            TextView tv;

            public MyViewHolder(View view)
            {
                super(view);
                tv = (TextView) view.findViewById(R.id.id_num);
            }
        }
    }
}

5.item_home布局文件

<TextView
    android:id="@+id/id_num"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:gravity="center"
    android:text="1" />


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值