Android layout using Swipe View and Tile Strip

谁说胖子不能爱 提交于 2019-12-13 01:17:45

问题


I'm making a new app, using the "Swipe View + Tile Strip" layout, but can't seem to figure out how to actually load different views into the fragments of the FragmentPagerAdapter?

Any help on this would be great (I'm still quite new to android development, so go easy ;) )


回答1:


Create a class that extends FragmentPagerAdapter.

Override getItem() and return a different fragment for each position.

Try something like this:

public class MyCustomFPAdapter extends FragmentPagerAdapter{

    public MyCustomFPAdapter (FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        if (position == 0) {
            return Fragment0.newInstance();
        } else if (position == 1) {
            return Fragment1.newInstance();
        } else if (position == 2) {
            return Fragment2.newInstance();
        } else if (position == 3) {
            return Fragment3.newInstance();
        } else {
            return DefaultFragment.newInstance();
        }
    }
}



回答2:


In a FragmentPagerAdapter you don't load Views, but Fragments.

Read the official documentation of FragmentPagerAdapter, which has a nice tutorial also. This is the first step to understand this Pager.

http://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html

Good luck!



来源:https://stackoverflow.com/questions/11651939/android-layout-using-swipe-view-and-tile-strip

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!