Issue with multiple Recyclerview inside Viewpager
Thanks for the answers, anyway this issue has got nothing to do with Recyclerview
or Viewpager
, it happened because of my misunderstanding on the variable reference. I change the ArrayList
somewhere else inside the activity. That affects the list in recyclerview
.
Android viewpager with recyclerview not working in fragment
It's hard to tell exactly due to the navigational structure of your app, but think the solution to your problem is to use the childFragmentManager inside of the ArtistBoardFragment. i.e, instead of
pageAdapter = new FragmentPagerAdapter(getActivity().getSupportFragmentManager()) ...
Use
pageAdapter = new FragmentPagerAdapter(getChildFragmentManager()) ...
ViewPager and RecyclerView issue with fragment transition
You're using the wrong FragmentManager
- for every fragment that is fully contained within the layout of another (such as your ViewPager2
managed fragments), you must use childFragmentManager
to properly nest the fragments.
viewPager.adapter = PagerAdapter(childFragmentManager, lifecycle)
This is required not only to restore your state properly (something which using the activity's supportFragmentManager
will not do), but to ensure that the parent fragment goes through its state transitions first and only then does the child fragments go through their transitions, fixing the "already executing transactions" issue.
RecyclerView infinite scroll not working inside ViewPager2
I ended up fixing this by just using a different infinite scroll RecyclerView class:
https://stackoverflow.com/a/26561717/14968122
ViewPager + RecyclerView issue in android
I see a lot of problems with your code, but let's get your UI displaying the subcategories since that's your main concern.
Change the getItem
in your adapter to this:
@Override
public Fragment getItem(int position) {
ArrayList<SubcategoryModel> subcategories = filelist.get(position).getItems();
Log.v("adapter", "getitem" + String.valueOf(position)+subcategories.size());
return FirstFragment.create(position,subcategories);
}
What caused the problem:
Let's focus on ArrayList<SubcategoryModel> subct
in your activity:
First your code did this:
for(int i = 0; i < filelist.size(); i++){
ArrayList<SubcategoryModel> subct=filelist.get(i).getItems();
// for(int j=0;j<subct.size();j++) ...
}
So at the end of this loop subct
is set the subcategories of the last category in filelist
.
After that, you did another loop to load the tabs, but that used a different subct
variable that was declared inside the loop, and that had no effect on the subct
field of your activity.
Then you created your view pager and adapter.
In your pager adapter you had this:
@Override
public Fragment getItem(int position) {
Log.v("adapter", "getitem" + String.valueOf(position)+subct.size());
return FirstFragment.create(position,subct);
}
Since subct
was set to the last category's subcategories from the loop before, every single fragment created was receiving those subcategories, no matter what position (category) the fragment was for. All I did was change the code to go back to filelist
and get the correct category (and subcategories) for the position of the fragment being created.
When you're writing code, you think about what you want the code to do. However, at the point where you run the code and discover you have a problem, you have to forget what you wanted the code to do, then pretend you're the computer and run the code in your head. You want to understand what effect every line of code is having. When you do it that way it's easier to find the problem.
Related Topics
How to Add Shadow to the Fab Provided with the Android Support Design Library
Notifications Fail to Display in Android Oreo (API 26)
Installing Ionic Npm Err! Tar.Unpack Error
Android APK File: Re-Activate Older APK File in Google Play Store
Execution Failed for Task App:Transformclasseswithdesugarfordebug Error on Android Studio 3.0 Beta 2
Topics on Firebase Cloud Messaging
Fragment-Fragment Communication in Android
Resource Linking Fails on Lstar
Android/Java: Transition/Migration from Proguard to R8
Android; Geocoder, Why Do I Get "The Service Is Not Available"
Java.Lang.Noclassdeffounderror: Com.Google.Android.Gms.R$Styleable in Android
Video Streaming Using Rtsp: Android
Permission Denied (Missing Internet Permission): But Permission Is Given