All Projects → sunfusheng → Multitype

sunfusheng / Multitype

【MultiType】可以轻松地实现RecyclerView显示多种数据类型,数据对应布局一对多、多对多、多对一,可以注册全局类型、局部类型、默认类型

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Multitype

Rendererrecyclerviewadapter
A single adapter with multiple view types for the whole project
Stars: ✭ 1,061 (+1226.25%)
Mutual labels:  recyclerview
Autorecycleradapter
Automated configuration RecyclerView.Adapter for Android
Stars: ✭ 67 (-16.25%)
Mutual labels:  recyclerview
Recyclerpager
Using RecyclerView and SnapHelper replace ViewPager
Stars: ✭ 73 (-8.75%)
Mutual labels:  recyclerview
Cardswipelayout
Use RecyclerView to achieve card swipe layout , like Tantan . (模仿探探卡片滑动效果的布局)
Stars: ✭ 1,081 (+1251.25%)
Mutual labels:  recyclerview
Tc Material Design
Série de artigos sobre o Material Design Android
Stars: ✭ 64 (-20%)
Mutual labels:  recyclerview
Collapsingrefresh
AppBarLayout+ViewPager+RecyclerView的刷新功能
Stars: ✭ 69 (-13.75%)
Mutual labels:  recyclerview
Circulerautoscrollingrecyclerview
Sample code of infinite rotation using RecyclerView. Built with Kotlin
Stars: ✭ 48 (-40%)
Mutual labels:  recyclerview
Rxbanner
一个灵活可制定的基于 Recyclerview 的轮播图控件,支持自动轮播,无限循环。 同时可关闭无限循环变成 引导页 ,带有引导完成接口回调
Stars: ✭ 77 (-3.75%)
Mutual labels:  recyclerview
Dividers For Recyclerview
📋 A simple demo to demonstrate how to draw dividers for RecyclerView
Stars: ✭ 65 (-18.75%)
Mutual labels:  recyclerview
Android Cardview Recyclerview
Let's play with Android CardView, RecyclerView, Retrofit and Picasso Library. You can read details procedure about those library in my Bengali blog site.
Stars: ✭ 72 (-10%)
Mutual labels:  recyclerview
Ultimaterefreshview
UltimateRefreshView 实现下拉刷新,上拉加载更多的轻量级库;支持RecyclerView ,ListView ,ScrollView & WebView
Stars: ✭ 64 (-20%)
Mutual labels:  recyclerview
Countdowntask
⌛️A countdown library for Android.
Stars: ✭ 64 (-20%)
Mutual labels:  recyclerview
Indexrecyclerview
[DEPRECATED] a Contact list implements by RecyclerView
Stars: ✭ 1,163 (+1353.75%)
Mutual labels:  recyclerview
Chameleon
🦎Chameleoen deals with the Status of RecyclerView.
Stars: ✭ 52 (-35%)
Mutual labels:  recyclerview
Gencycler
Gencycler is the fastest way to write RecyclerView adapters
Stars: ✭ 73 (-8.75%)
Mutual labels:  recyclerview
Sharebox
家庭看片神器,可以用手机播放电脑里的视频,也可以用电脑播放手机里的视频,使用简单,能稳定运行在后台,目前支持的设备有Windows,Mac,Android。
Stars: ✭ 51 (-36.25%)
Mutual labels:  recyclerview
Horizontal Calendar
A material horizontal calendar view for Android based on RecyclerView
Stars: ✭ 1,155 (+1343.75%)
Mutual labels:  recyclerview
Inifiniterecyclerview
Library for implementing endless loading list easily in Android applications
Stars: ✭ 79 (-1.25%)
Mutual labels:  recyclerview
Elements
⚒ Modular components for RecyclerView development enforcing clean, reusable and testable code, with built-in support for paging and complex hierarchies of data.
Stars: ✭ 75 (-6.25%)
Mutual labels:  recyclerview
Groupedrecyclerviewadapter
GroupedRecyclerViewAdapter可以很方便的实现RecyclerView的分组显示,并且每个组都可以包含组头、组尾和子项;可以方便实现多种Type类型的列表,可以实现如QQ联系人的列表一样的列表展开收起功能,还可以实现头部悬浮吸顶功能等。
Stars: ✭ 1,163 (+1353.75%)
Mutual labels:  recyclerview

MultiType Download

为实现RecyclerView显示多种类型数据,包括各种Headers、Footers,参考drakeet的扛鼎之作MultiType后, 着重优化了一对多的显示,即一种数据类型对应多种布局的情况,例如新闻数据类型(News.class)就可能显示 文本、左图、右图、大图、多图等多种item布局,面对这种情况就要根据数据中的类型字段(你指定属性的get()方法)去区分, 这里通过Java8的特性传递方法的引用,再通过KeyGenerator执行这个方法获取数据对应的值来解决这个问题的。

该库不仅可以显示同一种数据类型对应不同的layout,还可以显示不同数据类型对应不同的layout,如果你没有 通过MultiTypeRegistry全局注册或 通过MultiTypeAdapter局部注册过你的数据类型, 这个库不会让应用崩掉,会返回默认的提示layout,当然你也可以注册自己的默认数据类型,具体使用参考下面。

MultiState Download

MultiState 这个库为了管理请求数据的加载中、加载成功、加载失败、数据为空的情况,与MultiType配合使用更合适。

RecyclerViewWrapper Download

RecyclerViewWrapper 这个库结合【MultiType】和【MultiState】并使用了SmartRefreshLayout这个库来统一管理各个加载状态并简单封装了下拉刷新、上拉加载更多等相关功能,欢迎下载apk体验。

Sample预览图

Gradle配置

// MultiType
api 'com.sunfusheng:MultiType:<latest-version>'

// MultiState
api 'com.sunfusheng:MultiState:<latest-version>'

// RecyclerViewWrapper
compile 'com.sunfusheng:RecyclerViewWrapper:<latest-version>'

// 如果不想用库里版本的RecyclerView,可这样配置
api 'com.sunfusheng:RecyclerViewWrapper:<latest-version>', {
    exclude group: 'com.android.support'
}

// 如果同步不下来库的话,在工程下的 build.gradle 添加:
allprojects {
    repositories {
        maven { url 'https://dl.bintray.com/sfsheng0322/maven' }
    }
}

MultiType的使用

全局注册

MultiTypeRegistry.getInstance().register(News.class, News::getType, News.TYPE_TEXT, new TextBinder());
MultiTypeRegistry.getInstance().register(News.class, News::getType, News.TYPE_BIG_IMAGE, new BigImageBinder());
MultiTypeRegistry.getInstance().register(News.class, News::getType, News.TYPE_RIGHT_IMAGE, new RightImageBinder());
MultiTypeRegistry.getInstance().register(News.class, News::getType, News.TYPE_THREE_IMAGES, new ThreeImagesBinder());
MultiTypeRegistry.getInstance().register(Music.class, new MusicBinder());
MultiTypeRegistry.getInstance().register(Video.class, new VideoBinder());

注册默认或不支持类型

MultiTypeRegistry.getInstance().registerDefaultBinder(new NonsupportBinder());

局部注册,局部注册会覆盖全局的

MultiTypeAdapter multiTypeAdapter = new MultiTypeAdapter();
multiTypeAdapter.register(News.class, News::getType, News.TYPE_TEXT, new TextBinder());
multiTypeAdapter.register(News.class, News::getType, News.TYPE_BIG_IMAGE, new BigImageBinder());
multiTypeAdapter.register(News.class, News::getType, News.TYPE_RIGHT_IMAGE, new RightImageBinder());
multiTypeAdapter.register(News.class, News::getType, News.TYPE_THREE_IMAGES, new ThreeImagesBinder());
multiTypeAdapter.register(Music.class, new MusicBinder());
multiTypeAdapter.register(Video.class, new VideoBinder());

初始化,设置数据

RecyclerView recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(multiTypeAdapter);

multiTypeAdapter.setItems(@NonNull List<?> items);
multiTypeAdapter.notifyDataSetChanged();

MultiState的使用

属性 作用
loadingLayout 加载中布局
normalLayout 正常显示数据的布局
errorLayout 加载失败布局
emptyLayout 数据为空布局
loadingState 初始的加载状态

xml配置

<com.sunfusheng.multistate.MultiStateView
    android:id="@+id/multiStateView"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:loadingLayout="@layout/layout_loading"
    app:normalLayout="@layout/layout_recyclerview"
    app:errorLayout="@layout/layout_error"
    app:emptyLayout="@layout/layout_empty"
    app:loadingState="loading"/>

设置加载状态

multiStateView.setLoadingState(@LoadingState int loadingState);

APK下载地址,去手机上体验吧^_^


个人微信公众号


请作者喝杯咖啡^_^


关于我

GitHub: sunfusheng

个人邮箱: [email protected]

个人博客: sunfusheng.com

简书主页

新浪微博

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].