android-viewpager

Expected the adapter to be 'fresh' while restoring state

ぐ巨炮叔叔 提交于 2020-08-06 20:11:51
问题 I have a viewpager2 with multiple fragments in FragmentStateAdapter. Whenever I try to open a new fragment and then go back to my current one with viewpager2, I get an exception: Expected the adapter to be 'fresh' while restoring state. It seems FragmentStateAdapter is unable to properly restore its state as it is expecting it to be empty. What could I do to fix this ? 回答1: So my problem was that I was creating my FragmentStateAdapter inside my Fragment class field where it was only created

Expected the adapter to be 'fresh' while restoring state

折月煮酒 提交于 2020-08-06 20:06:23
问题 I have a viewpager2 with multiple fragments in FragmentStateAdapter. Whenever I try to open a new fragment and then go back to my current one with viewpager2, I get an exception: Expected the adapter to be 'fresh' while restoring state. It seems FragmentStateAdapter is unable to properly restore its state as it is expecting it to be empty. What could I do to fix this ? 回答1: So my problem was that I was creating my FragmentStateAdapter inside my Fragment class field where it was only created

Expected the adapter to be 'fresh' while restoring state

。_饼干妹妹 提交于 2020-08-06 20:02:36
问题 I have a viewpager2 with multiple fragments in FragmentStateAdapter. Whenever I try to open a new fragment and then go back to my current one with viewpager2, I get an exception: Expected the adapter to be 'fresh' while restoring state. It seems FragmentStateAdapter is unable to properly restore its state as it is expecting it to be empty. What could I do to fix this ? 回答1: So my problem was that I was creating my FragmentStateAdapter inside my Fragment class field where it was only created

ViewPager2 not able to dynamically add remove fragment

怎甘沉沦 提交于 2020-07-19 10:58:26
问题 Removing/Adding fragments at index results in unexpected behaviour in Viewpager2. This was not possible with ViewPager but expected to work with Viewpager2 . It causes duplicate fragments and out of sync TabLayout . Here is a demo project which reproduces this issue. There is a toggle button which removes a fragment and reattaches it at a particular index. In this case attached fragment should be green but it's blue and there are 2 blue fragments somehow. here is how my adapter looks class

Fragments in ViewPager2 does not respond to clicks if scroll position is 0

筅森魡賤 提交于 2020-07-19 05:25:12
问题 I am very glad that Google released ViewPager2 which is built on RecyclerView to solve a lot of issues that the old ViewPager has. I quickly replaced my old ViewPager codes to ViewPager2: Replace ViewPager with ViewPager2 in xml Replace FragmentPagerAdapter(FragmentManager) with FragmentStateAdapter(Fragment) ViewPager setup is as below: viewPager.adapter = fragmentAdapter val mediator = TabLayoutMediator(tabLayout, viewPager, true) { tab, position -> tab.text = fragmentAdapter.tabNames

SearchBar with TabLayout and Viewpager. SearchBar (EditText) doesn't filter through users, nor events

北慕城南 提交于 2020-06-29 03:37:06
问题 My SearchFragment is the host Fragment for two other Fragments: SearchUsersFragment and SearchEventsFragment . The way I have it organized is the TabLayout and Viewpager are in the SearchFragment , and the RecyclerView , Adapters , and ArrayList are in the two child Fragments. What I would like to do is implement a SearchBar ( EditText ), which I have already done in the SearchFragment and use that SearchBar to filter through the users (in SearchUsersFragment ) and events (in

Android Viewpager fragments refreshed when swiped

孤者浪人 提交于 2020-06-26 04:14:31
问题 I am new in Android and I don't really understand why a Fragment 's content which was added dynamically (for example some image which was added after a button click) is disappearing after scrolling some count of Fragment s and then come back. There is really simple code Activity and Fragment : public class MyActivity extends FragmentActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final ViewPager