当前位置:网站首页>Save state when viewpager is used with fragment fragmentpageradapter
Save state when viewpager is used with fragment fragmentpageradapter
2022-06-12 23:09:00 【And white】
The principle is hide show If you want to achieve other situations, you can replace
public class ViewPagerAdapter extends FragmentPagerAdapter {
private List<Fragment> fragmentList;
FragmentManager fragmentManager;
public ViewPagerAdapter(@NonNull FragmentManager fm) {
super(fm);
this.fragmentManager = fm;
}
@NonNull
@Override
public Fragment getItem(int position) {
return fragmentList.get(position);
}
@Override
public int getCount() {
return fragmentList.size();
}
public void setFragmentList(List<Fragment> fragmentList) {
if (this.fragmentList != null) this.fragmentList.clear();
this.fragmentList = fragmentList;
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
Fragment fragment = (Fragment) super.instantiateItem(container, position);
fragmentManager.beginTransaction().show(fragment).commit()
return fragment;
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
//super.destroyItem(container, position, object);
Fragment fragment = fragmentList.get(position);
fragmentManager.beginTransaction().hide(fragment).commit();
}
}
边栏推荐
- 80 lines of code to realize simple rxjs
- 年薪50万是一条线,年薪100万又是一条线…...
- Chapter 8 - shared model JUC
- Record 5 - the serial port of stm32f411ceu6 realizes the sending and receiving of fixed length data and variable length data
- MySQL row to column, column to row, multiple columns to one row, one row to multiple columns
- C language: how to give an alias to a global variable?
- [890. find and replace mode]
- [Yugong series] wechat applet in February 2022 - Reference
- Introduction to Quaternion
- Abstract methods and abstract classes
猜你喜欢

Summary of MySQL foundation view

The carrying capacity of L2 level ADAS increased by more than 60% year-on-year in January, and domestic suppliers "emerged"

Gb28181 protocol -- alarm

The annual salary of 500000 is one line, and the annual salary of 1million is another line

Shardingsphere-proxy-5.0.0 deployment table implementation (I)

Alcohol detector based on 51 single chip microcomputer
![Leetcode 890 finding and replacing patterns [map] the leetcode path of heroding](/img/a2/186439a6d50339ca7f299a46633345.png)
Leetcode 890 finding and replacing patterns [map] the leetcode path of heroding

Huawei officially entered the "front loading" stage, and the millimeter wave radar track entered the "localization +4d" cycle
![[Part VI] source code analysis and application details of countdownlatch [key]](/img/6e/085e257c938a8c7b88c12c36df83e1.jpg)
[Part VI] source code analysis and application details of countdownlatch [key]

管线中的坐标变换
随机推荐
Photoshop:ps how to enlarge a picture without blurring
四元数简介
Abstract methods and abstract classes
Mysql concat_ws、concat函数使用
[leetcode] the k-largest element in the array
【LeetCode】209. 长度最小的子数组
Leetcode 890 finding and replacing patterns [map] the leetcode path of heroding
Zhengzhou University of light industry -- development and sharing of harmonyos pet health system
lua 条件语句
Opencv source code compilation
Colab tutorial (super detailed version) and colab pro/colab pro+ usage evaluation
Function introduction and common terms of ZABBIX
基于51单片机的酒精检测仪
Analysis report on the "fourteenth five year plan" and the latest development trend of China's medical information industry from 2022 to 2028
Go时间格式化 赋值
Inventory of CV neural network models from 2021 to 2022
[890. find and replace mode]
OpenCV源代码编译
Avoid using asp Net core 3.0 to inject services for startup classes
Insight into China's smart medical industry in 2022