Search in sources :

Example 16 with FragmentStatePagerAdapter

use of android.support.v4.app.FragmentStatePagerAdapter in project making-apps-beautiful by ankurkotwal.

the class ArticleDetailActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_article_detail);
    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int i) {
            Bundle arguments = new Bundle();
            arguments.putString(ArticleDetailFragment.ARG_ITEM_ID, DummyContent.ITEMS.get(i).id);
            ArticleDetailFragment fragment = new ArticleDetailFragment();
            fragment.setArguments(arguments);
            return fragment;
        }

        @Override
        public int getCount() {
            return DummyContent.ITEMS.size();
        }
    });
    pager.setPageMarginDrawable(getResources().getDrawable(R.drawable.list_divider_holo_light));
    pager.setPageMargin((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));
    String startId = getIntent().getStringExtra(ArticleDetailFragment.ARG_ITEM_ID);
    for (int i = 0; i < DummyContent.ITEMS.size(); i++) {
        if (DummyContent.ITEMS.get(i).id.equals(startId)) {
            pager.setCurrentItem(i);
            return;
        }
    }
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) Bundle(android.os.Bundle) ViewPager(android.support.v4.view.ViewPager) Fragment(android.support.v4.app.Fragment)

Example 17 with FragmentStatePagerAdapter

use of android.support.v4.app.FragmentStatePagerAdapter in project RoboBinding-gallery by RoboBinding.

the class ViewPagerActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ViewPager viewPager = new ViewPager(this);
    viewPager.setId(R.id.viewPager);
    setContentView(viewPager);
    final MemoryProductStore productStore = MemoryProductStore.getInstance();
    FragmentManager fm = getSupportFragmentManager();
    viewPager.setAdapter(new FragmentStatePagerAdapter(fm) {

        @Override
        public int getCount() {
            return productStore.size();
        }

        @Override
        public Fragment getItem(int index) {
            return FragmentDemo.newInstance(index);
        }
    });
    int selectedProductIndex = getIntent().getIntExtra(FragmentDemo.EXTRA_PRODUCT_INDEX, 0);
    viewPager.setCurrentItem(selectedProductIndex);
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) MemoryProductStore(org.robobinding.gallery.model.MemoryProductStore) ViewPager(android.support.v4.view.ViewPager) Fragment(android.support.v4.app.Fragment)

Example 18 with FragmentStatePagerAdapter

use of android.support.v4.app.FragmentStatePagerAdapter in project Fragmentation by YoKeyword.

the class FragmentationDelegate method findStackFragment.

/**
     * find Fragment from FragmentStack
     */
@SuppressWarnings("unchecked")
<T extends SupportFragment> T findStackFragment(Class<T> fragmentClass, String toFragmentTag, FragmentManager fragmentManager) {
    fragmentManager = checkFragmentManager(fragmentManager, null);
    if (fragmentManager == null)
        return null;
    Fragment fragment = null;
    if (toFragmentTag == null) {
        // 如果是 查找Fragment时,则有可能是在FragmentPagerAdapter/FragmentStatePagerAdapter中,这种情况下,
        // 它们的Tag是以android:switcher开头,所以这里我们使用下面的方式
        List<Fragment> fragmentList = fragmentManager.getFragments();
        if (fragmentList == null)
            return null;
        int sizeChildFrgList = fragmentList.size();
        for (int i = sizeChildFrgList - 1; i >= 0; i--) {
            Fragment brotherFragment = fragmentList.get(i);
            if (brotherFragment instanceof SupportFragment && brotherFragment.getClass().getName().equals(fragmentClass.getName())) {
                fragment = brotherFragment;
                break;
            }
        }
    } else {
        fragment = fragmentManager.findFragmentByTag(toFragmentTag);
    }
    if (fragment == null) {
        return null;
    }
    return (T) fragment;
}
Also used : Fragment(android.support.v4.app.Fragment)

Example 19 with FragmentStatePagerAdapter

use of android.support.v4.app.FragmentStatePagerAdapter in project Timber by naman14.

the class ArtistBioFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_artist_bio, container, false);
    Artist artist = ArtistLoader.getArtist(getActivity(), artistID);
    LastFmClient.getInstance(getActivity()).getArtistInfo(new ArtistQuery(artist.name), new ArtistInfoListener() {

        @Override
        public void artistInfoSucess(LastfmArtist artist) {
        }

        @Override
        public void artistInfoFailed() {
        }
    });
    final MultiViewPager pager = (MultiViewPager) rootView.findViewById(R.id.tagspager);
    final FragmentStatePagerAdapter adapter = new FragmentStatePagerAdapter(getActivity().getSupportFragmentManager()) {

        @Override
        public int getCount() {
            return 20;
        }

        @Override
        public Fragment getItem(int position) {
            return ArtistTagFragment.newInstance(position);
        }
    };
    pager.setAdapter(adapter);
    return rootView;
}
Also used : LastfmArtist(com.naman14.timber.lastfmapi.models.LastfmArtist) Artist(com.naman14.timber.models.Artist) FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) ArtistInfoListener(com.naman14.timber.lastfmapi.callbacks.ArtistInfoListener) MultiViewPager(com.naman14.timber.widgets.MultiViewPager) View(android.view.View) ArtistQuery(com.naman14.timber.lastfmapi.models.ArtistQuery) LastfmArtist(com.naman14.timber.lastfmapi.models.LastfmArtist)

Example 20 with FragmentStatePagerAdapter

use of android.support.v4.app.FragmentStatePagerAdapter in project Timber by naman14.

the class StyleSelectorFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_style_selector, container, false);
    if (ACTION.equals(Constants.SETTINGS_STYLE_SELECTOR_NOWPLAYING)) {
    }
    pager = (MultiViewPager) rootView.findViewById(R.id.pager);
    adapter = new FragmentStatePagerAdapter(getChildFragmentManager()) {

        @Override
        public int getCount() {
            return 6;
        }

        @Override
        public Fragment getItem(int position) {
            selectorFragment = SubStyleSelectorFragment.newInstance(position, ACTION);
            return selectorFragment;
        }

        @Override
        public int getItemPosition(Object object) {
            return POSITION_NONE;
        }
    };
    pager.setAdapter(adapter);
    scrollToCurrentStyle();
    return rootView;
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) View(android.view.View) Fragment(android.support.v4.app.Fragment)

Aggregations

FragmentStatePagerAdapter (android.support.v4.app.FragmentStatePagerAdapter)21 Fragment (android.support.v4.app.Fragment)20 ViewPager (android.support.v4.view.ViewPager)13 Bundle (android.os.Bundle)11 View (android.view.View)6 Toolbar (android.support.v7.widget.Toolbar)3 BindView (butterknife.BindView)3 MaterialViewPager (com.github.florent37.materialviewpager.MaterialViewPager)3 HeaderDesign (com.github.florent37.materialviewpager.header.HeaderDesign)3 PagerAdapter (android.support.v4.view.PagerAdapter)2 TextView (android.widget.TextView)2 RecyclerViewFragment (com.github.florent37.materialviewpager.sample.fragment.RecyclerViewFragment)2 Intent (android.content.Intent)1 StateListDrawable (android.graphics.drawable.StateListDrawable)1 FragmentManager (android.support.v4.app.FragmentManager)1 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)1 RecyclerView (android.support.v7.widget.RecyclerView)1 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)1 WebView (android.webkit.WebView)1 AbsListView (android.widget.AbsListView)1