使用FragmentPagerAdapter 可以处理多个 Fragment 页面的横向滑动。
但在使用过程中,会发现当从fragmentA切换到fragmentB页面时,需要的功能是fragmentB的页面能够重新加载数据,而不是用FragmentManager里面缓存的fragmentB。网上的方法很多,但是很多没有用,所以我使用了定义一个静态变量的方法来实现,做下笔记。
1、在fragmentB里定义一个静态的listview。
2、在activity里的实现OnPageChangeListener接口,并实现onPageSelected(int index)方法,使用switch流程控制语句监听当切换到第二页(index=1)时,实现重新加载数据的方法。
3、new出一个fragmentB,然后使用fragmentB里的静态变量listview适配数据,完成重新加载数据的功能。