turing-tech / MaterialScrollBar

An Android library that brings the Material Design 5.1 sidebar to pre-5.1 devices.
Apache License 2.0
778 stars 126 forks source link

Using same RecyclerViewAdapter twice at different fragments MaterialScrollBar wont work on second adapter #117

Closed duruer closed 6 years ago

duruer commented 6 years ago

Hello, we are using this library on our app. And we have got a little problem.

We have got a MainActivity which it has 3 fragments on ViewPager.

We have got a MediaListAdapter which is RecyclerViewAdapter. We are using this adapter on 2 fragment at the same time. So first fragment works great but second fragment's scrollbar not showen or not working. If you pull from right to left on screen you can see scrollbar on second fragment. But that scrollbar work for first fragment.

turing-tech commented 6 years ago

I've gotten a sample app to run with the same adapter. Do the recyclerviews share the same ID?

duruer commented 6 years ago

Idk which ID you mean

turing-tech commented 6 years ago

The ID of the recycler views which share the adapter.

duruer commented 6 years ago

If you mean id on layout, yeah we use same layout for 2 fragment and 2 adapters id are same

turing-tech commented 6 years ago

The issue ssems to be that the scroll bar in the second fragment is picking out the recyclerView in the first fragment because they share the same ID and it gets confused. You can fix this by manually setting the recyclerView with the .setRecyclerView() method in onCreateView of your second fragment, passing in the correct recyclerView.

duruer commented 6 years ago

Sorry, i don't understand great. We have got one fragment class, we use that as two fragment. I mean in ViewPager we add same fragment twice. That means twice layout, twice code. I can devote which fragment is it in code.

But what do you mean set manually recyclerView. We using Android Databinding.

turing-tech commented 6 years ago

In the onCreateView method of the fragment that's inserted twice, add the following

RecyckerView rv = view.findViewById(R.id. ); DragScrollBar/TouchScrollBar scrollBar = view.findViewById(R.id.); scrollBar.serRecyclerView(rv);

duruer commented 6 years ago

Sorry, i tried but not worked. Still same problem