Questions tagged [fragmentstateadapter]

35 questions
8
votes
3 answers

NotifyDataSetChanged not working in FragmentStateAdapter with Viewpager2

I am making a file selection page with viewpager2 with FragmentStateAdapter. In one of the pages I show all mounted storage devices on which I would like to tap to view the contents but I want the contents to be on another fragment. I want to…
5
votes
0 answers

How to set custom tag for viewpager2 fragments?

How to set custom tag for viewpager2 fragments? How can i set a tag for viewpager fragments? The above question provides answers for ViewPager. But how can this be done for ViewPager2?
4
votes
3 answers

FragmentStateAdapter not calling createFragment when notifyDataSetChanged is called

I am using a ViewPager2 together with a FragmentStateAdapter. public class MyAdapter extends FragmentStateAdapter { public MyAdapter(@NonNull Fragment fragment) { super(fragment); } @NonNull @Override public Fragment…
MaxxOr
  • 55
  • 2
  • 6
3
votes
2 answers

RecyclerView onClick event is not working with SwipeRefreshLayout?

Before using FragmentStateAdapter. I was using FragmentPagerAdapter then everything was fine but when I migrated from FragmentPagerAdapter to FragmentStateAdapter to reduce memory usage. The issue that I'm facing is that when RecyclerView is at the…
3
votes
2 answers

Replacement for BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT

androidx.fragment.app.FragmentStatePagerAdapter is deprecated and developers are urged to switch to androidx.viewpager2.adapter.FragmentStateAdapter How can we get the same functionality with FragmentStateAdapter that…
3
votes
2 answers

How to update Fragments in Tablayout? (Viewpager2, FragmentStateAdapter)

I create the initial content with the data from an arraylist(i get it from firebase) the data changes every 15 minutes, how do i call a recreation or how do i settext from the mainactivity to the fragments / how do i update the textviews in the…
2
votes
0 answers

Viewpager2 with fragment and diffutil problem

I have a problem with viewpager2. Problem is There is a viewpager2 with Fragment, FragmentStateAdapter, DiffUtil If page is selected, update fragment list dynamically. (remove, add) Here is a example. A, B(current), C -> swipe to C -> A, B,…
2
votes
1 answer

Dagger-Android: ViewModel not destroyed when fragment destroyed

in my project I am using Dagger2 to inject ViewModels into fragments. override val viewModel: AllStockListTabViewModel by viewModels ({this}, {viewModelFactory}) To briefly explain my situation, I have a fragment that uses fragment state adapter…
Austin
  • 63
  • 1
  • 7
2
votes
1 answer

How to replace a fragment in a FragmentStateAdapter

I have a "main" fragment that contains tabs on the side, and when I click on any of those tabs, the ViewPager2 of the "main" fragment jumps to the specific fragment (each fragment is of a different class) in the FragmentStateAdapter. Let's say that…
2
votes
1 answer

What is purpose of overriding `containsItem` and `getItemId` in `FragmentStateAdapter`?

What is purpose of overriding containsItem and getItemId in FragmentStateAdapter? Are these overrides required if one is passing in new lists to the FragmentStatePagerAdapter implementation and calling notifyDataSetChanged? From the doc, appears…
the_prole
  • 8,275
  • 16
  • 78
  • 163
2
votes
2 answers

How do I dynamically add and delete fragments with viewpager2 and fragmentstateadapter?

so I've been trying to dynamically add and delete fragments from my application for months now. I recently migrated over to viewpager2 and fragmentstateadapter but to no avail. My goal is to delete a fragment at a specific location completely, but…
2
votes
0 answers

Android ViewPager2 fragment destroying behavior does not comply with offscreenPageLimit

I am using ViewPager2 with FragmentStateAdapter and I am setting offscreenPageLimit to 1. Each Fragment contains a surface (obtained via a TextureView) to be drawn on. The code is fairly simple: package com.example.testapplication import…
Robin
  • 10,052
  • 6
  • 31
  • 52
1
vote
1 answer

findFragmentByTag keeps returning Null in Android using ViewPager

I was trying to pass data from the Parent Activity to the viewPager, and I found a solution using findFragmentByTag but it returns Null and I'm not sure what I missed. The example I found used a deprecated FragmentPagerAdapter and I think maybe…
1
vote
1 answer

How to remove useless fragments in ViewPager2

How to destroy retain Fragments or unused Fragments(Fragment with number 1-4) in ViewPager2 when right swap. I want only retain one Fragment in left of visible Fragment (Fragment 5)? private static class SettingAdapter extends FragmentStateAdapter…
Sabrina N
  • 150
  • 11
1
vote
0 answers

FragmentStateAdapter createFragment - when do you actually need to create new fragments/when do fragments get deleted?

I have been learning how to use FragmentStateAdapter and ViewPager2, and one of the issues I'm encountering is the logic behind what to do in createFragment. I know a fragment must be returned, but some sample apps have a list of fragments passed…
Zach
  • 3,909
  • 6
  • 25
  • 50
1
2 3