Git Product home page Git Product logo

yaodeming / xrv Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dsiner/pulllayout

0.0 1.0 0.0 999 KB

Common RecyclerView for Android ——Common list, pager, pull down refresh, load more, add header/footer, multi-type layout support, common adapter, drag and drop sort; 通用列表、分页加载、下拉刷新、加载更多、可添加header/footer、多类型布局支持、通用Adapter、拖拽排序

License: Apache License 2.0

Java 100.00%

xrv's Introduction

Common RecyclerView for Android

License API Download Readme

Demo

Screenshot Screenshot

Setup

Maven:

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

or Gradle:

    implementation 'com.dsiner.lib:xrv:1.1.2'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.nineoldandroids:library:2.4.0'

Usage

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

Step 1. Get reference

        // Step 1: Get reference
        XRecyclerView xrvList = (XRecyclerView) this.findViewById(R.id.xrv_list);

Step 2. Set layoutmanager

        xrvList.showAsList(); // LinearLayoutManager

Step 3. Set header (optional)

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

Step 4-1. New adapter(simple type)

        public class SimpleAdapter extends CommonAdapter<Bean> {
            /**
             * @param context: Context
             * @param datas: Filled data source
             * @param layoutId: Single type layout
             */
            public SimpleAdapter(Context context, List<Bean> datas, int layoutId) {
                super(context, datas, layoutId);
            }
        
            @Override
            public void convert(int position, CommonHolder holder, Bean item) {
                // Assigned by the universal holder method
                holder.setText(R.id.tv_des, "P:" + position + "_" + item.name);
            }
        }
        SimpleAdapter adapter = new SimpleAdapter(this, datas, R.layout.item_0);

Step 4-2. Or new adapter(multiple type)

        public class MultipleAdapter extends CommonAdapter<Bean> {
        
            /**
             * @param context: Context
             * @param datas:  Filled data source
             * @param multiItemTypeSupport: Multiple layout type support
             */
            public MultipleAdapter(Context context, List<Bean> datas, MultiItemTypeSupport<Bean> multiItemTypeSupport) {
                super(context, datas, multiItemTypeSupport);
            }
        
            @Override
            public void convert(int position, CommonHolder holder, Bean item) {
                // Step 4-2-3: First determine the mLayoutId layout type, and then manipulate the controls through the universal 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) {
                // Step 4-2-2: Return layout layout based on type
                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) {
                // Step 4-2-1: Get type
                return bean.type;
            }
        });

Step 5. Set adapter

        xrvList.setAdapter(adapter);

Step 6. Set listener

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

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

More usage see Demo

Latest Changes

Thanks

  • XRecyclerView - 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.

xrv's People

Contributors

dsiner avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.