A RecyclerView that implements pullrefresh and loadingmore featrues.you can use it like a standard RecyclerView

Overview

XRecyclerView

a RecyclerView that implements pullrefresh , loadingmore and header featrues.you can use it like a standard RecyclerView. you don't need to implement a special adapter .qq 群478803619 Screenshots

demo

on real device it is much more smoother. Usage

gradle

// 1.6.0 is the main
compile 'com.jcodecraeer:xrecyclerview:1.6.0'

just like a standard RecyclerView

LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setAdapter(mAdapter);

pull to refresh and load more

the pull to refresh and load more featrue is enabled by default. we provide a callback to trigger the refresh and LoadMore event.

 mRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
    @Override
    public void onRefresh() {
       //refresh data here
    }

    @Override
    public void onLoadMore() {
       // load more data here
    }
});

new function of 1.5.7 version.

mRecyclerView
    .getDefaultRefreshHeaderView() // get default refresh header view
    .setRefreshTimeVisible(true);  // make refresh time visible,false means hiding

// if you are not sure that you are 100% going to
// have no data load back from server anymore,do not use this
@Deprecated
public void setEmptyView(View emptyView) {
    ...
}

new function of 1.5.6 version,fixed a memory leak problem,use the code below to release XR's memory

// any time,when you finish your activity or fragment,call this below
if(mRecyclerView != null){
    mRecyclerView.destroy(); // this will totally release XR's memory
    mRecyclerView = null;
}

new function of 1.5.3 version,you can use XR in the sticky scroll model now,like the code below,the demo activity is 'LinearStickyScrollActivity'

final View topView = findViewById(R.id.topView);
final View tabView = findViewById(R.id.tabView);
final View content = findViewById(R.id.contentView);

final StickyScrollLinearLayout s = findViewById(R.id.StickyScrollLinearLayout);
s.addOnLayoutChangeListener(
        new View.OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                if(s.getContentView() != null)
                    return;
                // 放在这里是为了等初始化结束后再添加,防止 height 获取 =0
                // add from here just in case they height==0
                s.setInitInterface(
                        new StickyScrollLinearLayout.StickyScrollInitInterface() {
                            @Override
                            public View setTopView() {
                                return topView;
                            }

                            @Override
                            public View setTabView() {
                                return tabView;
                            }

                            @Override
                            public View setContentView() {
                                return content;
                            }
                        }
                );
            }
        }
);

call notifyItemRemoved or notifyItemInserted, remember to use the functions inside XRecyclerView

listData.remove(pos);
mRecyclerView.notifyItemRemoved(listData,pos);

and of course you have to tell our RecyclerView when the refreshing or loading more work is done. you can use

mRecyclerView.loadMoreComplete();

to control when the item number of the screen is list.size-2,we call the onLoadMore

mRecyclerView.setLimitNumberToCallLoadMore(2); // default is 1

to notify that the loading more work is done. and

 mRecyclerView.refreshComplete();

to notify that the refreshing work is done.

here is what we get:

default

call refresh() manually(I change the previous setRefreshing() method to refresh() )

mRecyclerView.refresh();

custom refresh and loading more style

pull refresh and loading more style is highly customizable.

custom loading style

the loading effect we use the AVLoadingIndicatorView . and it is built in(make a little change). we provide all the effect in AVLoadingIndicatorView library besides we add a system style. you can call

mRecyclerView.setRefreshProgressStyle(int style);

and

mRecyclerView.setLaodingMoreProgressStyle(int style);

to set the RefreshProgressStyle and LaodingMoreProgressStyle respectively.

for example

mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);

refreshloadingballspinfade

mRecyclerView.setLaodingMoreProgressStyle(ProgressStyle.SquareSpin);

loadingmoresquarespin

BallPulse effect

BallPulse

all the effect can be get in the ProgressStyle class

public class ProgressStyle {
    public static final int SysProgress=-1;
    public static final int BallPulse=0;
    public static final int BallGridPulse=1;
    public static final int BallClipRotate=2;
    public static final int BallClipRotatePulse=3;
    public static final int SquareSpin=4;
    public static final int BallClipRotateMultiple=5;
    public static final int BallPulseRise=6;
    public static final int BallRotate=7;
    public static final int CubeTransition=8;
    public static final int BallZigZag=9;
    public static final int BallZigZagDeflect=10;
    public static final int BallTrianglePath=11;
    public static final int BallScale=12;
    public static final int LineScale=13;
    public static final int LineScaleParty=14;
    public static final int BallScaleMultiple=15;
    public static final int BallPulseSync=16;
    public static final int BallBeat=17;
    public static final int LineScalePulseOut=18;
    public static final int LineScalePulseOutRapid=19;
    public static final int BallScaleRipple=20;
    public static final int BallScaleRippleMultiple=21;
    public static final int BallSpinFadeLoader=22;
    public static final int LineSpinFadeLoader=23;
    public static final int TriangleSkewSpin=24;
    public static final int Pacman=25;
    public static final int BallGridBeat=26;
    public static final int SemiCircleSpin=27;
}

refresh arrow icon

we provide a default arrow icon:

ic_pulltorefresh_arrow

but if you don't like it,you can replace it with any other icon you want. just call

mRecyclerView.setArrowImageView(R.drawable.iconfont_downgrey);

customarrow

disable refresh and load more featrue

if you don't want the refresh and load more featrue(in that case,you probably dont'n need the lib neither),you can call

mRecyclerView.setPullRefreshEnabled(false);

and

mRecyclerView.setPullRefreshEnabled(true);

in which false means disabled ,true means enabled. ##Header you can add header to XRecyclerView,just call addHeaderView().

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

if you like ,you can add two header

View header =   LayoutInflater.from(this).inflate(R.layout.recyclerview_header, (ViewGroup)findViewById(android.R.id.content),false);
View header1 =   LayoutInflater.from(this).inflate(R.layout.recyclerview_header1, (ViewGroup)findViewById(android.R.id.content),false);
mRecyclerView.addHeaderView(header);
mRecyclerView.addHeaderView(header1);

License

Copyright 2015 jianghejie

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.
Comments
  • Scrapped or attached views may not be recycled. isScrap:false isAttached:true

    Scrapped or attached views may not be recycled. isScrap:false isAttached:true

    Hi , I got some crash when my list have one or two item then I pull down to refresh. Here is message : FATAL EXCEPTION: main Process: com.portalbeanz.chezzypizza, PID: 31417 java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false isAttached:true at android.support.v7.widget.RecyclerView$Recycler.recycleViewHolderInternal(RecyclerView.java:5736) at android.support.v7.widget.RecyclerView$Recycler.quickRecycleScrapView(RecyclerView.java:5843) at android.support.v7.widget.RecyclerView$LayoutManager.removeAndRecycleScrapInt(RecyclerView.java:8501) at android.support.v7.widget.RecyclerView.dispatchLayoutStep3(RecyclerView.java:3656) at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3323) at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3844) at android.view.View.layout(View.java:16630) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586) at android.widget.LinearLayout.onLayout(LinearLayout.java:1495) at android.view.View.layout(View.java:16630) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079) at android.view.View.layout(View.java:16630) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586) at android.widget.LinearLayout.onLayout(LinearLayout.java:1495) at android.view.View.layout(View.java:16630) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336) at android.widget.FrameLayout.onLayout(FrameLayout.java:273) at android.view.View.layout(View.java:16630) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586) at android.widget.LinearLayout.onLayout(LinearLayout.java:1495) at android.view.View.layout(View.java:16630) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336) at android.widget.FrameLayout.onLayout(FrameLayout.java:273) at android.view.View.layout(View.java:16630) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586) at android.widget.LinearLayout.onLayout(LinearLayout.java:1495) at android.view.View.layout(View.java:16630) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336) at android.widget.FrameLayout.onLayout(FrameLayout.java:273) at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2678) at android.view.View.layout(View.java:16630) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2171) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1931) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858) at android.view.Choreographer.doCallbacks(Choreographer.java:670) at android.view.Choreographer.doFrame(Choreographer.java:606) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

    duplicate help wanted 
    opened by duongnv1996 10
  • How to remove header ?

    How to remove header ?

    i had to add header before set adapter into recyclerView, but after i call request header no data found. And i want to remove that header, is possible now ?

    opened by derohimat 8
  • Adapter 中notifyItemRemoved()报错

    Adapter 中notifyItemRemoved()报错

    删除列表中的首末条目时:java.lang.IllegalArgumentException: Called attach on a child which is not detached ViewHolder{41cede38 position=7 id=-1, oldPos=-1, pLpos:-1} 烦解

    opened by wujuan 7
  • 将下拉刷新 和上拉加载禁掉 会导致EmptyView显示不出来

    将下拉刷新 和上拉加载禁掉 会导致EmptyView显示不出来

    mRecyclerView.setLoadingMoreEnabled(false); mRecyclerView.setPullRefreshEnabled(false); mRecyclerView.setEmptyView(mEmptyView); 将下拉刷新 和上啦加载禁掉 会导致EmptyView显示不出来 。看了源码 觉得应该不会出现这个问题,但确实是有。

    opened by chen2174471 7
  • NestedScrollView 嵌套 XRecyclerView 无法自动加载更多

    NestedScrollView 嵌套 XRecyclerView 无法自动加载更多

    <android.support.design.widget.CoordinatorLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
    
                <android.support.design.widget.AppBarLayout
                    android:id="@+id/app_bar_layout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal">
    
                    <android.support.design.widget.CollapsingToolbarLayout
                        android:id="@+id/collapsing_toolbar_layout"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:layout_scrollFlags="scroll|exitUntilCollapsed" >
    
                        . . .
    
                    </android.support.design.widget.CollapsingToolbarLayout>
    
                    <!-- 标签 -->
                    <android.support.design.widget.TabLayout . . .  />
    
                </android.support.design.widget.AppBarLayout>
    
                <android.support.v4.view.ViewPager
                    android:id="@+id/view_pager"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    
            </android.support.design.widget.CoordinatorLayout>
    
    
    在上面的viewpager中用
    
    <android.support.v4.widget.NestedScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
                    <com.jcodecraeer.xrecyclerview.XRecyclerView
                        android:id="@+id/rv_goods_list"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />
    
                </LinearLayout>
    
            </android.support.v4.widget.NestedScrollView>
    
    XRecyclerView无法自动加载更多。
    opened by KXwonderful 6
  • Loadmore not trigger when put the XRecylerview inside PullRefreshlayout

    Loadmore not trigger when put the XRecylerview inside PullRefreshlayout

    Hi there, i have a problem here that if i disable the refresh header and put the recyclerview inside PullRefreshLayout, this line always wrong :

    int adjAdapterItemCount = layoutManager.getItemCount() + getHeaders_includingRefreshCount() + (pullRefreshEnabled ? 1 : 2);
    .....
    && lastVisibleItemPosition >= adjAdapterItemCount - limitNumberToCallLoadMore
    

    and the loadmore never trigger.So how can i fix it

    help wanted 
    opened by cuong292 0
  • 当XRecyclerView 添加超过两个headers 将触发 IllegalStateException: ViewHolder views must not be attached when created.

    当XRecyclerView 添加超过两个headers 将触发 IllegalStateException: ViewHolder views must not be attached when created.

    复现场景:

    先查看一个header的XRecyclerView(AActivity);再查看两个header的XRecyclerView(BActivity)就会触发 IllegalStateException: ViewHolder views must not be attached when created.

    经过分析发现 XRecyclerView.sHeaderTypes 为 被 static 修饰。

    public void addHeaderView(View view) {
        if(mHeaderViews == null || sHeaderTypes == null)
            return;
        sHeaderTypes.add(HEADER_INIT_INDEX + mHeaderViews.size());
        mHeaderViews.add(view);
        if (mWrapAdapter != null) {
            mWrapAdapter.notifyDataSetChanged();
        }
    }
    

    addHeaderView 中 sHeaderTypes.add 和 mHeaderViews.add 肯定会由于多个列表的多次addHeaderView导致数据不同步。最后出现

    第一次加载列表 sHeaderTypes 已为 [10002] 第二次加载列表 sHeaderTypes 为 [10002,10002,10003]

    且经过 XRecyclerView.WrapAdaptergetItemViewType -> onCreateViewHolder -> getHeaderViewByType 会导致两次获取到同一个 headerView 。

    opened by Vove7 0
Owner
XRecyclerView
origin owner @jianghejie
XRecyclerView
RecyclerView extension library which provides advanced features. (ex. Google's Inbox app like swiping, Play Music app like drag and drop sorting)

Advanced RecyclerView This RecyclerView extension library provides Google's Inbox app like swiping, Play Music app like drag-and-drop sorting and expa

Haruki Hasegawa 5.2k Dec 23, 2022
Carousel Recyclerview let's you create carousel layout with the power of recyclerview by creating custom layout manager.

Carousel Recyclerview let's you create carousel layout with the power of recyclerview by creating custom layout manager.

Jack and phantom 504 Dec 25, 2022
TikTok-RecyclerView - This is a demo app built using 'Koin' a new dependency injection framework for Android along with RecyclerView and ExoPlayer2.

TikTok-RecyclerView Demo About This is a demo app built using 'Koin' a new dependency injection framework for Android along with RecyclerView and ExoP

Baljeet Singh 19 Dec 28, 2022
Pagination-RecyclerView - Simple and easy way to Paginating a RecyclerView

Pagination-RecyclerView Simple and easy way to Paginating a RecyclerView Android

Rakshit Nawani 0 Jan 3, 2022
the library is a loop RecyclerView(expression), can show some effects when display

CircleRecyclerView the library is a loop RecyclerView, can show some effects when display screenshot CircularViewMode ScaleXViewMode & ScaleYViewMode

Matt Yao 704 Jan 5, 2023
A very easy-to-use and non-intrusive implement of Swipe to dismiss for RecyclerView.

RecyclerViewSwipeDismiss A very easy-to-use and non-intrusive implement of Swipe to dismiss for RecyclerView. Preview How to use Add these lines to yo

xcodebuild 431 Nov 23, 2022
A very easy-to-use and non-intrusive implement of Swipe to dismiss for RecyclerView.

RecyclerViewSwipeDismiss A very easy-to-use and non-intrusive implement of Swipe to dismiss for RecyclerView. Preview How to use Add these lines to yo

xcodebuild 431 Nov 23, 2022
Elegant design and convenient to use RecyclerView adapter library based on Kotlin DSL.

xAdapter: Kotlin DSL 风格的 Adapter 封装 1、简介 该项目是 KotlinDSL 风格的 Adapter 框架封装,用来简化 Adapter 调用,思想是采用工厂和构建者方式获取 Adapter 避免代码中定义大量的 Adapter 类。该项目在 BRVAH 的 Ada

ShouHeng 17 Oct 9, 2022
Add RecyclerView, use Adapter class and ViewHolder to display data.

فكرة المشروع في هذا المشروع سنقوم بعرض قائمة من البيانات للطلاب على واجهة تطبيق Android بإستخدام: مفهوم RecyclerView مفهوم Adapter مفهوم ViewModel محت

Shaima Alghamdi 3 Nov 18, 2021
ANDROID. ChipsLayoutManager (SpanLayoutManager, FlowLayoutManager). A custom layout manager for RecyclerView which mimicric TextView span behaviour, flow layouts behaviour with support of amazing recyclerView features

ChipsLayoutManager This is ChipsLayoutManager - custom Recycler View's LayoutManager which moves item to the next line when no space left on the curre

Oleg Beloy 3.2k Dec 25, 2022
RecyclerView : SleepQualityTracker with RecyclerView app

RecyclerView - SleepQualityTracker with RecyclerView app SleepQualityTracker with RecyclerView This app builds on the SleepQualityTracker developed pr

Kevin 2 May 14, 2022
Just another one easy-to-use adapter for RecyclerView :rocket:

Elementary RecyclerView Adapter Another one easy-to-use adapter for RecyclerView ?? Features: DSL-like methods for building adapters similar to Jetpac

Roman Andrushchenko 29 Jan 6, 2023
A RecyclerView Adapter which allows you to have an Infinite scrolling list in your apps

Infinite Recycler View A RecyclerView Adapter which allows you to have an Infinite scrolling list in your apps. This library offers you a custom adapt

IB Sikiru 26 Dec 10, 2019
Square Cycler API allows you to easily configure an Android RecyclerView declaratively in a succinct way.

Square Cycler – a RecyclerView API The Square Cycler API allows you to easily configure an Android RecyclerView declaratively in a succinct way. Desig

Square 791 Dec 23, 2022
RetroDialer - Custom view like a retro telephone dialer

RetroDialer Custom view like a retro telephone dialer Demo

Kshitij Kumar 7 Feb 5, 2022
A RecyclerView(advanced and flexible version of ListView in Android) with refreshing,loading more,animation and many other features.

UltimateRecyclerView Master branch: Dev branch: Project website:https://github.com/cymcsg/UltimateRecyclerView Description UltimateRecyclerView is a R

MarshalChen 7.2k Jan 2, 2023
[] Super fast and easy way to create header for Android RecyclerView

DEPRECATED I created this library back in the day when I thought RecyclerView was all new and difficult. Writing an adapter that could inflate multipl

Bartek Lipinski 1.3k Dec 28, 2022
Android Library to provide swipe, click and other functionality to RecyclerView

RecyclerViewEnhanced Android Library to provide swipe, click and other functionality to RecyclerView Usage Add this to your build.gradle file dependen

Nikhil Panju 1k Dec 29, 2022