Android layout using Swipe View and Tile Strip

2019-07-29 04:01发布

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 ;) )

2条回答
甜甜的少女心
2楼-- · 2019-07-29 04:05

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!

查看更多
Ridiculous、
3楼-- · 2019-07-29 04:14

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();
        }
    }
}
查看更多
登录 后发表回答