0

我有一个 SplashScreen,它是一个 ViewPager,我需要在点击时将登录片段添加到它。

这是我的寻呼机适配器:

public class SplashSAdapter extends PagerAdapter {

    Context ssContext;
    Activity _activity;
    private int[] ssImages = new int[] { R.drawable.splashscreen1,R.drawable.splashscreen2, R.drawable.splashscreen3 };

    public SplashSAdapter(Context ssContext, Activity activity) {
        this.ssContext = ssContext;
        this._activity = activity;
    }

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

    @Override
    public boolean isViewFromObject(View ssView, Object ssObject) {
        return ssView == ((ImageView) ssObject);
    }

    @Override
    public Object instantiateItem(ViewGroup ssContainer, int ssPosition) {
        ImageView ssImageView = new ImageView(ssContext);
        ssImageView.setScaleType(ImageView.ScaleType.FIT_XY);
        ssImageView.setImageResource(ssImages[ssPosition]);
        ((ViewPager) ssContainer).addView(ssImageView, 0);
        ssImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                onClickSplashScreen();
            }
        });

        return ssImageView;
    }

    @Override
    public void destroyItem(ViewGroup ssContainer, int ssPosition,
            Object ssObject) {
        ((ViewPager) ssContainer).removeView((ImageView) ssObject);
    }

    public void onClickSplashScreen(){
}

那么,onClickSplashScreen,如何在其中添加 Fragment?

4

2 回答 2

0

您应该使用 FragmentPagerAdapter 而不是 PagerAdapter,

示例可以在这里找到 http://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html

于 2013-08-15T11:11:10.800 回答
-2
FragmentManager fragmentManager = this._activity.getSupportFragmentManager()
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
ExampleFragment fragment = new ExampleFragment();
fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.commit();

这会帮助你吗?

于 2013-08-15T11:06:16.113 回答