Implement ViewPager combined with Fragment to achieve infinite loop switching. This is also done in the adapter. Of course, it can also be implemented using sliding monitoring.
import .; import .; import .; import ; import ; public class adapter extends FragmentPagerAdapter { private ArrayList<Fragment> fragmentList; public adapter(FragmentManager fm) { super(fm); } public adapter(FragmentManager fm, ArrayList<Fragment> fragmentList) { super(fm); =fragmentList; } @Override public Fragment getItem(int position) { //The reason why position is not processed here is because the getItem method is //Called in the instantiateItem method. Just process before calling //position is enough to avoid repeated processing return (position); } @Override public int getCount() { return Integer.MAX_VALUE; } @Override public int getItemPosition(Object object) { return (object); } @Override public Object instantiateItem(ViewGroup container, int position) { //Processing position. Let the array subscript fall into [0,) to prevent cross-border position = position % (); return (container, position); } }
After actual inspection, 4 fragments must be transmitted, otherwise there will be problems if you slide to the right. I don’t know the reason...
If you want to realize the page turning effect of the answering interface, you can use this method. You can create a ReadFragment and then new 4 objects of this Fragment. The common processing of different pages can be directly implemented in ReadFragment. When turning pages, the parameters that need to be changed on each page can be obtained in the sliding listener to obtain these 4 objects.
Fragment a=new ReadFragment(); Fragment b=new ReadFragment(); Fragment c=new ReadFragment(); Fragment d=new ReadFragment(); list=new ArrayList<Fragment>(); (a); (b); (c); (d); (new adapter(getSupportFragmentManager(),list));
(new () { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {} @Override public void onPageSelected(int position) { //Processing position. Let position fall into [0,) to prevent array from crossing boundaries position = position % (); ReadFragment fragment= (ReadFragment) (position); //Get the selected fragment at this time (); //When turning pages, the parameters that need to be changed are implemented using this method. In ReadFragment, the modifier must use public ... } @Override public void onPageScrollStateChanged(int state) {} });
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.