shuhart/BubblePagerIndicator

Exception in Recyclerview

karandeep26 opened this issue · 12 comments

This library is not supported for ViewPager inside the recyclerview?

Could you provide a stacktrace and a layout example?

In my project it works perfectly.

multiple viewpager indicators in recyclerView?

I am facing problem with multiple viewpagers in a recyclerView.

Show your xml structure.

`

<data>
    <import type="java.util.List"/>
    <import type="android.view.View"/>

    <variable
        name="vm"
        type="com.knudge.me.viewmodel.newsfeed.MultiplePictureViewModel" />
</data>

<include
    android:id="@+id/header"

    layout="@layout/item_news_feed_header"/>


<android.support.v4.view.ViewPager
    android:id="@+id/view_pager"
    android:clipToPadding="false"
    app:layout_constraintTop_toBottomOf="@id/header"
    android:layout_width="match_parent"
    android:layout_marginBottom="@dimen/app_spacing_4"
    android:layout_height="300dp"/>


<RelativeLayout
    android:id="@+id/indicator_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<include
    android:visibility="visible"
    android:id="@+id/footer"
    layout="@layout/item_news_feed_bottom"
   />
    <com.shuhart.bubblepagerindicator.BubblePageIndicator
        android:id="@+id/indicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        app:bpi_radius="6dp"
        app:bpi_fillColor="@color/black"
        app:bpi_pageColor="@color/card_progress_yellow"
        app:bpi_marginBetweenCircles="6dp"
        app:bpi_risingCount="@integer/default_bubble_indicator_rising_count"/>
</RelativeLayout>
`

Earlier I was getting exception while scrolling the recyclerView regarding the no observer exception. I resolved that by setting the viewPager of your library to null initially. Now I am facing problem with indicator not changing in some cases after scrolling probably because currentPage is setting to 0 at some point.

But where is RecyclerView in the layout?

And you mentioned multiple BubblePagerIndicator widgets in the layout. So far, I don't understand how it's done.

I am using recyclerView which has viewPager as an item.

I don't see any problem with that. I use this library in production in exact same way as you are. RecyclerView and ViewPager as an item. Could you reproduce and describe those cases when something goes wrong?

To reproduce:

  • Create a RecyclerView that contains one row with a ViewPager + Indicator and 100 rows with something else
  • Scroll down and up
  • Crash

Why is this crashing?
The RecyclerView tries to recycle the row that contains the ViewPager & Indicator. It first sets a new adapter to the ViewPager. Then it calls setViewPager, which tries to unregister the new adapter instead of the old one from callbacks. That leads to a crash.

How can we solve this?
Add a clearViewPager method to the BubblePageIndicator and call this from the unbind method.

Fixed in 1.1.0