Android – Detect when the last item in a RecyclerView is visible

You can create a callback in your adapter which will send a message to your activity/fragment every time when the last item is visible. For example, you can implement this idea in onBindViewHolder method @Override public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) { if(position==(getItemCount()-1)){ // here goes some code // callback.sendMessage(Message); } //do the rest of … Read more

Recyclerview Adapter and Glide – same image every 4-5 rows

The answers here are incorrect, although they’re on the right track. You need to call Glide#clear(), not just set the image drawable to null. If you don’t call clear(), an async load completing out of order may still cause view recycling issues. Your code should look like this: @Override public void onBindViewHolder(ViewHolder holder, int position) … Read more

CoordinatorLayout using the ViewPager’s RecyclerView

Chris Banes has posted a sample on Github which shows exactly what you want to do. Here is the xml file that defines how one can indirectly attach a coordinator layout to the viewpager’s fragments. <android.support.design.widget.CoordinatorLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:id=”@+id/main_content” android:layout_width=”match_parent” android:layout_height=”match_parent”> <android.support.design.widget.AppBarLayout android:id=”@+id/appbar” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:theme=”@style/ThemeOverlay.AppCompat.Dark.ActionBar”> <android.support.v7.widget.Toolbar android:id=”@+id/toolbar” android:layout_width=”match_parent” android:layout_height=”?attr/actionBarSize” android:background=”?attr/colorPrimary” app:popupTheme=”@style/ThemeOverlay.AppCompat.Light” app:layout_scrollFlags=”scroll|enterAlways” /> <android.support.design.widget.TabLayout … Read more

How to have a ListView/RecyclerView inside a parent RecyclerView?

I got this issue few days ago and finally solved it. All you have to do is @override the layout manager onMeasure function as below: CustomLinearLayoutManager public class CustomLinearLayoutManager extends LinearLayoutManager { private static final String TAG = CustomLinearLayoutManager.class.getSimpleName(); public CustomLinearLayoutManager(Context context) { super(context); } public CustomLinearLayoutManager(Context context, int orientation, boolean reverseLayout) { super(context, orientation, … Read more

How to set RecyclerView Max Height

ConstraintLayout offers maximum height for its children. <android.support.constraint.ConstraintLayout 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”> <ListView android:layout_width=”0dp” android:layout_height=”wrap_content” android:scrollbars=”vertical” app:layout_constrainedHeight=”true” app:layout_constraintBottom_toBottomOf=”parent” app:layout_constraintEnd_toEndOf=”parent” app:layout_constraintHeight_max=”300dp” app:layout_constraintStart_toStartOf=”parent” app:layout_constraintTop_toTopOf=”parent” /> </android.support.constraint.ConstraintLayout>

Put an indeterminate progressbar as footer in a RecyclerView grid

It is very simple to do that. The solution is to use the same approach of the LinearLayoutManager with a GridLayoutManager and then use the method setSpanSizeLookup on the LayoutManager like this: mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { switch(myAdapter.getItemViewType(position)){ case MyAdapter.VIEW_TYPES.Product: return 1; case MyAdapter.VIEW_TYPES.Progress: return 2; //number of columns of the … Read more

Recyclerview not call any Adapter method :onCreateViewHolder,onBindViewHolder,

Other than @SanatiSharif’s and @sohrab’s answer, you have to follow below mandatory step. Make sure you call setLayoutManager, something like below. recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); before setting adapter into recyclerView, otherwise it is not going to work. You can customize it if you need. this link will give you some idea of how LayoutManager works.

How to put RecyclerView inside NestedScrollView?

The following is my new updated answer: <android.support.v4.widget.NestedScrollView android:id=”@+id/scrollview” android:layout_width=”match_parent” android:layout_height=”match_parent” android:fillViewport=”true” app:layout_behavior=”@string/appbar_scrolling_view_behavior”> <RelativeLayout android:layout_width=”match_parent” android:layout_height=”wrap_content”> <android.support.v7.widget.CardView android:id=”@+id/cardview1″ android:layout_width=”match_parent” android:layout_height=”wrap_content” android:layout_margin=”@dimen/card_margin”> <LinearLayout style=”@style/Widget.CardContent” android:layout_width=”match_parent” android:layout_height=”wrap_content”> <TextView android:layout_width=”match_parent” android:layout_height=”wrap_content” android:text=”Info CardView1″ android:textAppearance=”@style/TextAppearance.AppCompat.Title” /> <TextView android:layout_width=”match_parent” android:layout_height=”wrap_content” android:text=”@string/cheese_ipsum” /> </LinearLayout> </android.support.v7.widget.CardView> <android.support.v7.widget.CardView android:id=”@+id/cardview2″ android:layout_width=”match_parent” android:layout_height=”wrap_content” android:layout_below=”@+id/cardview1″ android:layout_margin=”@dimen/card_margin”> <LinearLayout style=”@style/Widget.CardContent” android:layout_width=”match_parent” android:layout_height=”wrap_content”> <TextView android:layout_width=”match_parent” android:layout_height=”wrap_content” android:text=”Info CardView2″ android:textAppearance=”@style/TextAppearance.AppCompat.Title” … Read more

Inconsistency detected in RecyclerView, How to change contents of RecyclerView while scrolling

Edit: The bug is fixed now, if you’re still getting the same Exception, please make sure you’re updating your Adapter data source only from the main thread and calling appropriate adapter notify method after it. Old answer: It seems to be a bug in RecyclerView, it’s reported here and here. Hopefully it will be fixed … Read more