0

我按照本教程显示标签栏,如 googleplay http://blog.peterkuterna.net/2011/09/viewpager-meets-swipey-tabs.html 但如何在每个标签栏上添加不同的活动?像 myactivity1.java、myactivity2.java、myactivity3.java?? 请帮我把这个放在哪里???

      @Override

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_swipeytab);

mViewPager = (ViewPager) findViewById(R.id.viewpager);
mTabs = (SwipeyTabs) findViewById(R.id.swipeytabs);

SwipeyTabsPagerAdapter adapter = new SwipeyTabsPagerAdapter(this, 
 getSupportFragmentManager());
mViewPager.setAdapter(adapter);
mTabs.setAdapter(adapter);
mViewPager.setOnPageChangeListener(mTabs);
mViewPager.setCurrentItem(0);
4

1 回答 1

0

改变:

private class SwipeyTabsPagerAdapter extends FragmentPagerAdapter implements
                    SwipeyTabsAdapter {

            private final Context mContext;

            public SwipeyTabsPagerAdapter(Context context, FragmentManager fm) {
                    super(fm);

                    this.mContext = context;
            }

            @Override
            public Fragment getItem(int position) {
                    return SwipeyTabFragment.newInstance(TITLES[position]);
            }

            @Override
            public int getCount() {
                    return TITLES.length;
            }

            public TextView getTab(final int position, SwipeyTabs root) {
                    TextView view = (TextView) LayoutInflater.from(mContext).inflate(
                                    R.layout.swipey_tab_indicator, root, false);
                    view.setText(TITLES[position]);
                    view.setOnClickListener(new OnClickListener() {
                            public void onClick(View v) {
                                    mViewPager.setCurrentItem(position);
                            }
                    });

                    return view;
            }

    }

至:

private class SwipeyTabsPagerAdapter extends FragmentPagerAdapter implements
                    SwipeyTabsAdapter {

            private final Context mContext;

            public SwipeyTabsPagerAdapter(Context context, FragmentManager fm) {
                    super(fm);

                    this.mContext = context;
            }

            @Override
            public Fragment getItem(int position) {
        switch(position){
            case 0: //If the position is 0, the SwipeyTabFragment will be shown, do this for each fragment.
                SwipeyTabFragment frag = new SwipeyTabFragment();
                return frag;
        }
        return null;
            }

            @Override
            public int getCount() {
                    return TITLES.length;
            }

            public TextView getTab(final int position, SwipeyTabs root) {
                    TextView view = (TextView) LayoutInflater.from(mContext).inflate(
                                    R.layout.swipey_tab_indicator, root, false);
                    view.setText(TITLES[position]);
                    view.setOnClickListener(new OnClickListener() {
                            public void onClick(View v) {
                                    mViewPager.setCurrentItem(position);
                            }
                    });

                    return view;
            }

    }
于 2013-06-13T18:28:23.063 回答