Skip to content
/ Xrv Public
forked from Dsiner/PullLayout

Common RecyclerView for Android,通用列表、分页加载、下拉刷新、加载更多、可添加header/footer、多类型布局支持、通用Adapter、拖拽排序

Notifications You must be signed in to change notification settings

BeWaterMF/Xrv

 
 

Repository files navigation

Common RecyclerView for Android

License Download

Demo

Screenshot Screenshot

Setup

Maven:

<dependency>
  <groupId>com.dsiner.lib</groupId>
  <artifactId>xrv</artifactId>
  <version>1.1.0</version>
</dependency>

or Gradle:

compile 'com.dsiner.lib:xrv:1.1.0'

Usage

    <com.d.lib.xrv.XRecyclerView
        android:id="@+id/xrv_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

Step1. 获取引用

        //step1:获取引用
        XRecyclerView xrvList = (XRecyclerView) this.findViewById(R.id.xrv_list);

Step2. 设置LayoutManager

        xrvList.showAsList();//listview展现形式

Step3. setHeader(可选)

        View header = LayoutInflater.from(this).inflate(R.layout.view_header, (ViewGroup) findViewById(android.R.id.content), false);
        xrvList.addHeaderView(header);

Step4-1. new Adapter(SimpleType)

        public class SimpleAdapter extends CommonAdapter<Bean> {
            /**
             * @param context:context
             * @param datas:填充数据源
             * @param layoutId:单一类型布局layout
             */
            public SimpleAdapter(Context context, List<Bean> datas, int layoutId) {
                super(context, datas, layoutId);
            }
        
            @Override
            public void convert(int position, CommonHolder holder, Bean item) {
                //通过通用holder方法赋值
                holder.setText(R.id.tv_des, "P:" + position + "_" + item.name);
            }
        }
        SimpleAdapter adapter = new SimpleAdapter(this, datas, R.layout.item_0);

Step4-2. or new Adapter(MultipleType)

        public class MultipleAdapter extends CommonAdapter<Bean> {
        
            /**
             * @param context:context
             * @param datas:填充数据源
             * @param multiItemTypeSupport:多布局类型支持
             */
            public MultipleAdapter(Context context, List<Bean> datas, MultiItemTypeSupport<Bean> multiItemTypeSupport) {
                super(context, datas, multiItemTypeSupport);
            }
        
            @Override
            public void convert(int position, CommonHolder holder, Bean item) {
                //先判断mLayoutId布局类型,后通过通用holder操控控件
                switch (holder.mLayoutId) {
                    case R.layout.item_0:
                        ...
                        break;
                    case R.layout.item_1:
                        ...
                        break;
                    case R.layout.item_2:
                        ...
                        break;
                    case R.layout.item_3:
                        ...
                        break;
                }
            }
        }
        
        MultipleAdapter adapter = new MultipleAdapter(MultipleXRvActivity.this, datas, new MultiItemTypeSupport<Bean>() {
            @Override
            public int getLayoutId(int viewType) {
                //step4-2:根据type返回layout布局
                switch (viewType) {
                    case 0:
                        return R.layout.item_0;
                    case 1:
                        return R.layout.item_1;
                    case 2:
                        return R.layout.item_2;
                    case 3:
                        return R.layout.item_3;
                    default:
                        return R.layout.item_0;
                }
            }

            @Override
            public int getItemViewType(int position, Bean bean) {
                //step4-1:获取type类型
                return bean.type;
            }
        });

Step5. setAdapter

        xrvList.setAdapter(adapter);

Step6. setListener

        xrvList.setLoadingListener(new IRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                ...
            }

            @Override
            public void onLoadMore() {
                ...
            }
        });

More usage see Demo

Thanks

  • XRecyclerView -a RecyclerView that implements pullrefresh , loadingmore and header featrues

Licence

Copyright 2017 D

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Common RecyclerView for Android,通用列表、分页加载、下拉刷新、加载更多、可添加header/footer、多类型布局支持、通用Adapter、拖拽排序

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%