Search in sources :

Example 71 with Fragment

use of android.support.v4.app.Fragment in project hellocharts-android by lecho.

the class ViewPagerChartsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_pager_charts);
    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });
    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the callback (listener) for when
        // this tab is selected.
        actionBar.addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}
Also used : ViewPager(android.support.v4.view.ViewPager) ActionBar(android.support.v7.app.ActionBar)

Example 72 with Fragment

use of android.support.v4.app.Fragment in project ParallaxSplash by leerduo.

the class ParallaxContainer method setUp.

/**
     * 指定引导页的所有页面布局文件
     *
     * @param childIds
     */
public void setUp(int... childIds) {
    //根据布局文件数组,初始化所有的Fragment
    fragments = new ArrayList<>();
    for (int i = 0; i < childIds.length; i++) {
        ParallaxFragment f = new ParallaxFragment();
        Bundle args = new Bundle();
        //页面索引
        args.putInt("index", i);
        //Fragment中需要加载的布局文件id
        args.putInt("layoutId", childIds[i]);
        f.setArguments(args);
        fragments.add(f);
    }
    //实例化适配器
    MainActivity activity = (MainActivity) getContext();
    adapter = new ParallaxPagerAdapter(activity.getSupportFragmentManager(), fragments);
    //实例化ViewPager
    ViewPager vp = new ViewPager(getContext());
    vp.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    vp.setId(R.id.parallax_pager);
    //绑定
    vp.setAdapter(adapter);
    addView(vp, 0);
    //在翻页的过程中,不断根据视图的标签中对应的动画参数,改变视图的位置或者透明度
    vp.setOnPageChangeListener(this);
}
Also used : Bundle(android.os.Bundle) ViewGroup(android.view.ViewGroup) ViewPager(android.support.v4.view.ViewPager)

Example 73 with Fragment

use of android.support.v4.app.Fragment in project cube-sdk by liaohuqiu.

the class CubeFragmentActivity method goToThisFragment.

private void goToThisFragment(FragmentParam param) {
    int containerId = getFragmentContainerId();
    Class<?> cls = param.cls;
    if (cls == null) {
        return;
    }
    try {
        String fragmentTag = getFragmentTag(param);
        FragmentManager fm = getSupportFragmentManager();
        if (DEBUG) {
            CLog.d(LOG_TAG, "before operate, stack entry count: %s", fm.getBackStackEntryCount());
        }
        CubeFragment fragment = (CubeFragment) fm.findFragmentByTag(fragmentTag);
        if (fragment == null) {
            fragment = (CubeFragment) cls.newInstance();
        }
        if (mCurrentFragment != null && mCurrentFragment != fragment) {
            mCurrentFragment.onLeave();
        }
        fragment.onEnter(param.data);
        FragmentTransaction ft = fm.beginTransaction();
        if (fragment.isAdded()) {
            if (DEBUG) {
                CLog.d(LOG_TAG, "%s has been added, will be shown again.", fragmentTag);
            }
            ft.show(fragment);
        } else {
            if (DEBUG) {
                CLog.d(LOG_TAG, "%s is added.", fragmentTag);
            }
            ft.add(containerId, fragment, fragmentTag);
        }
        mCurrentFragment = fragment;
        ft.addToBackStack(fragmentTag);
        ft.commitAllowingStateLoss();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    mCloseWarned = false;
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction)

Example 74 with Fragment

use of android.support.v4.app.Fragment in project android-topeka by googlesamples.

the class CategorySelectionActivity method attachCategoryGridFragment.

private void attachCategoryGridFragment() {
    FragmentManager supportFragmentManager = getSupportFragmentManager();
    Fragment fragment = supportFragmentManager.findFragmentById(R.id.category_container);
    if (!(fragment instanceof CategorySelectionFragment)) {
        fragment = CategorySelectionFragment.newInstance();
    }
    supportFragmentManager.beginTransaction().replace(R.id.category_container, fragment).commit();
    setProgressBarVisibility(View.GONE);
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) CategorySelectionFragment(com.google.samples.apps.topeka.fragment.CategorySelectionFragment) CategorySelectionFragment(com.google.samples.apps.topeka.fragment.CategorySelectionFragment) Fragment(android.support.v4.app.Fragment)

Example 75 with Fragment

use of android.support.v4.app.Fragment in project android-advancedrecyclerview by h6ah4i.

the class VerticalSwipeableExampleActivity method onNotifyItemPinnedDialogDismissed.

// implements ItemPinnedMessageDialogFragment.EventListener
@Override
public void onNotifyItemPinnedDialogDismissed(int itemPosition, boolean ok) {
    final Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_LIST_VIEW);
    getDataProvider().getItem(itemPosition).setPinned(ok);
    ((VerticalSwipeableExampleFragment) fragment).notifyItemChanged(itemPosition);
}
Also used : ItemPinnedMessageDialogFragment(com.h6ah4i.android.example.advrecyclerview.common.fragment.ItemPinnedMessageDialogFragment) Fragment(android.support.v4.app.Fragment) DialogFragment(android.support.v4.app.DialogFragment) ExampleDataProviderFragment(com.h6ah4i.android.example.advrecyclerview.common.fragment.ExampleDataProviderFragment)

Aggregations

Fragment (android.support.v4.app.Fragment)663 FragmentTransaction (android.support.v4.app.FragmentTransaction)233 Bundle (android.os.Bundle)149 View (android.view.View)140 FragmentManager (android.support.v4.app.FragmentManager)134 DialogFragment (android.support.v4.app.DialogFragment)80 TextView (android.widget.TextView)59 FragmentInstruction (de.madcyph3r.example.example.FragmentInstruction)48 MaterialMenu (de.madcyph3r.materialnavigationdrawer.menu.MaterialMenu)48 MaterialItemSectionFragment (de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment)48 FragmentDummy (de.madcyph3r.example.example.FragmentDummy)43 Intent (android.content.Intent)41 ViewPager (android.support.v4.view.ViewPager)38 FragmentActivity (android.support.v4.app.FragmentActivity)34 ImageView (android.widget.ImageView)32 BaseFragment (com.waz.zclient.pages.BaseFragment)29 ArrayList (java.util.ArrayList)28 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)25 Button (android.widget.Button)24 ActionBar (android.support.v7.app.ActionBar)23