rubensousa / GravitySnapHelper

A SnapHelper that snaps a RecyclerView to an edge.
Apache License 2.0
5k stars 615 forks source link

java.lang.IllegalStateException: An instance of OnFlingListener already set. #23

Closed Kolyall closed 7 years ago

Kolyall commented 7 years ago

Here is my code:

SnapHelper snapHelper = new GravitySnapHelper(Gravity.START);
snapHelper.attachToRecyclerView(mRecyclerView);

but sometimes the issue occurs:

FATAL EXCEPTION: main
                                                                        Process: by.gramoplayer.android, PID: 12195
                                                                        java.lang.IllegalStateException: An instance of OnFlingListener already set.
                                                                            at android.support.v7.widget.SnapHelper.setupCallbacks(SnapHelper.java:114)
                                                                            at android.support.v7.widget.SnapHelper.attachToRecyclerView(SnapHelper.java:102)
                                                                            at com.github.rubensousa.gravitysnaphelper.GravitySnapHelper.attachToRecyclerView(GravitySnapHelper.java:47)
evanhalley commented 7 years ago

Set the recycler view fling listener to null (this is what worked for me).

mRecyclerView.setOnFlingListener(null);

Kolyall commented 7 years ago

I added check for isSnapHelperAttached or not

rubensousa commented 7 years ago

Fixed on 1.3. Now the FlingListener is set to null before the SnapHelper attaches itself to the RecyclerView.

ghost commented 6 years ago

getting same error with an example

 snapAdapter.addSnap(new Snap(Gravity.CENTER_HORIZONTAL, "Snap center", apps));
 snapAdapter.addSnap(new Snap(Gravity.CENTER_HORIZONTAL, "Snap center", apps));
snapAdapter.addSnap(new Snap(Gravity.CENTER_HORIZONTAL, "Snap center", apps));
snapAdapter.addSnap(new Snap(Gravity.CENTER_HORIZONTAL, "Snap center", apps));
snapAdapter.addSnap(new Snap(Gravity.CENTER_HORIZONTAL, "Snap center", apps));
snapAdapter.addSnap(new Snap(Gravity.CENTER_HORIZONTAL, "Snap center", apps));
snapAdapter.addSnap(new Snap(Gravity.CENTER_HORIZONTAL, "Snap center", apps));
snapAdapter.addSnap(new Snap(Gravity.CENTER_HORIZONTAL, "Snap center", apps));
snapAdapter.addSnap(new Snap(Gravity.CENTER_HORIZONTAL, "Snap center", apps));

scrolling to the bottom and then up produces this error