Java Code Examples for android.support.v4.view.ViewPager#setAdapter()

The following examples show how to use android.support.v4.view.ViewPager#setAdapter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CollectionDemoActivity.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_collection_demo);

    // Create an adapter that when requested, will return a fragment representing an object in
    // the collection.
    // 
    // ViewPager and its adapters use support library fragments, so we must use
    // getSupportFragmentManager.
    mDemoCollectionPagerAdapter = new DemoCollectionPagerAdapter(getSupportFragmentManager());

    // Set up action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home button should show an "Up" caret, indicating that touching the
    // button will take the user one step up in the application's hierarchy.
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Set up the ViewPager, attaching the adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mDemoCollectionPagerAdapter);
}
 
Example 2
Source File: GalleryPagerFragment.java    From catnut with MIT License 6 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
	ViewPager viewPager = (ViewPager) view;
	viewPager.setAdapter(new FragmentStatePagerAdapter(getFragmentManager()) {
		@Override
		public Fragment getItem(int position) {
			return SimpleImageFragment.getFragment(mUrls.get(position));
		}

		@Override
		public int getCount() {
			return mUrls.size();
		}
	});
	viewPager.setPageTransformer(true, new PageTransformer.ZoomOutPageTransformer());
	viewPager.setCurrentItem(mCurrentIndex);
}
 
Example 3
Source File: SampleIconsDefault.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.simple_icons);

    getSupportActionBar().setCustomView(R.layout.actionbar_icon_indicator);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(false);
    TestFragmentAdapter mAdapter = new TestFragmentAdapter(getSupportFragmentManager());
    ViewPager mPager = (ViewPager)findViewById(R.id.pager);
    mPager.setAdapter(mAdapter);

    IconPageIndicator  mIndicator = (IconPageIndicator) getSupportActionBar().getCustomView().findViewById(R.id.indicator);
    mIndicator.setViewPager(mPager);
}
 
Example 4
Source File: MainActivity.java    From XModulable with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity_main);
    Toolbar toolbar = findViewById(R.id.main_toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setHomeButtonEnabled(false); // 设置导航按钮无效
    getSupportActionBar().setDisplayHomeAsUpEnabled(false); // 不显示导航按钮
    getSupportActionBar().setDisplayShowTitleEnabled(true); // 显示标题

    TabLayout tabLayout = findViewById(R.id.main_tab_layout);
    ViewPager viewPager = findViewById(R.id.main_pager);
    LinkedHashMap<String, Fragment> fragments = new LinkedHashMap<>(3);
    fragments.put("main", new MainFragment());
    if (liveModule != null) {
        fragments.put("live", liveModule.getLiveService().createLiveEntranceFragment());
    }
    if (imModule != null) {
        fragments.put("im", imModule.getIMService().createIMEntranceFragment());
    }
    viewPager.setAdapter(new MainPagerAdapter(getSupportFragmentManager(), fragments));
    tabLayout.setupWithViewPager(viewPager);
}
 
Example 5
Source File: PagerHeaderFragment.java    From ScrollableLayout with MIT License 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View layout = inflater.inflate(R.layout.fragment_pagerheader, container, false);
    ViewPager viewPager = (ViewPager) layout.findViewById(R.id.viewpager);
    // 头部图片集
    ViewPager vpImage = (ViewPager) layout.findViewById(R.id.imagepager);
    vpImage.setAdapter(new MyHeadPicAdapter(getActivity()));

    // ScrollableLayout
    mScrollLayout = (ScrollableLayout) layout.findViewById(R.id.scrollableLayout);
    PagerSlidingTabStrip pagerSlidingTabStrip = (PagerSlidingTabStrip) layout.findViewById(R.id.pagerStrip);
    initFragmentPager(viewPager, pagerSlidingTabStrip, mScrollLayout);
    setupPullToRefresh(layout);

    return layout;
}
 
Example 6
Source File: ExploreActivity.java    From glimmr with Apache License 2.0 5 votes vote down vote up
private void initViewPager() {
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
    GlimmrPagerAdapter adapter = new GlimmrPagerAdapter(
            getSupportFragmentManager(), viewPager, mActionBar, CONTENT) {
        @Override
        public Fragment getItemImpl(int position) {
            switch (position) {
                case INTERESTING_PAGE:
                    return RecentPublicPhotosFragment.newInstance();
            }
            return null;
        }
    };
    viewPager.setAdapter(adapter);

    //TitlePageIndicator indicator =
        //(TitlePageIndicator) findViewById(R.id.indicator);
    //if (indicator != null) {
        //indicator.setViewPager(viewPager);
    //} else {
        //mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        //viewPager.setOnPageChangeListener(adapter);
        //for (String title : CONTENT) {
            //ActionBar.Tab newTab = mActionBar.newTab().setText(title);
            //newTab.setTabListener(adapter);
            //mActionBar.addTab(newTab);
        //}
    //}
}
 
Example 7
Source File: ActivityUtilsTestActivity.java    From android-utilset with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	// TODO Auto-generated method stub
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_activityutils);
	
	pagerAdapter = new ActivityUtilsPagerAdapter(getSupportFragmentManager());
	
	actionBar = getActionBar();
	actionBar.setHomeButtonEnabled(false);
	actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
	
	viewPager = (ViewPager) findViewById(R.id.viewPagerActivityUtils);
	viewPager.setAdapter(pagerAdapter);
	viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

		@Override
		public void onPageSelected(int position) {
			// TODO Auto-generated method stub
			if (position == 0) {
				ScreenUtils.setScreenOn(ActivityUtilsTestActivity.this);
			}
			else if (position == 1) {
				ScreenUtils.clearScreenOn(ActivityUtilsTestActivity.this);
			}
			 actionBar.setSelectedNavigationItem(position);
		}
		
	});
	
	for (int i=0;i<pagerAdapter.getCount();++i) {
		actionBar.addTab(actionBar.newTab().setText(pagerAdapter.getPageTitle(i)).setTabListener(this));
	}
	
	ScreenUtils.setScreenOn(this);
}
 
Example 8
Source File: Conference.java    From mConference-Framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setupViewPager(ViewPager viewPager) {
    TabAdapter adapter = new TabAdapter(getSupportFragmentManager());
    adapter.addFragment(new About(), "About");
    adapter.addFragment(new Venue(), "Venue");
    adapter.addFragment(new Register(), "Register");
    adapter.addFragment(new Sponsor(), "Sponsors");
    viewPager.setAdapter(adapter);
}
 
Example 9
Source File: MainActivity.java    From ParallaxViewPagers with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState)
  {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  final ViewPager viewPager=(ViewPager)findViewById(R.id.viewPager);
  final ViewPager viewPager2=(ViewPager)findViewById(R.id.viewPager2);
  viewPager.setAdapter(new MyPagerAdapter());
  viewPager2.setAdapter(new MyPagerAdapter());
  /**the current master viewPager*/
  AtomicReference<ViewPager> masterRef=new AtomicReference<>();
  viewPager.addOnPageChangeListener(new ParallaxOnPageChangeListener(viewPager,viewPager2,masterRef));
  viewPager2.addOnPageChangeListener(new ParallaxOnPageChangeListener(viewPager2,viewPager,masterRef));
  }
 
Example 10
Source File: LoginActivity.java    From BitkyShop with MIT License 5 votes vote down vote up
void setTabLayout() {
  TabLayout tabLayout = (TabLayout) findViewById(R.id.loginActivity_tabLayout);
  ViewPager viewPager = (ViewPager) findViewById(R.id.loginActivity_viewPager);
  //初始化各fragment
  LoginPhoneFragment loginPhoneFragment = new LoginPhoneFragment();
  //   LoginLegacyFragment loginLegacyFragment = new LoginLegacyFragment();
  //   loginLegacyFragment.setActivity(this);
  loginPhoneFragment.setActivity(this);
  //将fragment装进列表中
  List<Fragment> fragmentList = new ArrayList<>();
  fragmentList.add(loginPhoneFragment);
  //   fragmentList.add(loginLegacyFragment);
  //将名称加载tab名字列表,正常情况下,我们应该在values/arrays.xml中进行定义然后调用
  List<String> titleList = new ArrayList<>();
  titleList.add("手机号一键登录");
  //   titleList.add("传统登录");
  //设置TabLayout的模式
  tabLayout.setTabMode(TabLayout.MODE_FIXED);
  //为TabLayout添加tab名称
  tabLayout.addTab(tabLayout.newTab().setText(titleList.get(0)));
  //  tabLayout.addTab(tabLayout.newTab().setText(titleList.get(1)));
  FragmentManager fragmentManager = getSupportFragmentManager();
  FragmentPagerAdapter fAdapter = new FindTabAdapter(fragmentManager, fragmentList, titleList);
  //viewpager加载adapter
  viewPager.setAdapter(fAdapter);
  //TabLayout加载viewpager
  tabLayout.setupWithViewPager(viewPager);
}
 
Example 11
Source File: ConfigureFragment.java    From Storm with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle sis) {

    final View view = inflater.inflate(R.layout.fragment_configure, parent, false);

    mTitle = findView(view, R.id.configure_title);
    mPages = findView(view, R.id.configure_pages);

    final BaseConfigureChildFragment<?> [] fragments = getFragments();

    mAdapter = new ConfigurePagerAdapter(getChildFragmentManager(), fragments);

    final ViewPager viewPager = findView(view, R.id.view_pager);
    viewPager.setOffscreenPageLimit(fragments.length - 1);
    final ViewPager.OnPageChangeListener onPageChangeListener = new ViewPagerOnPageChangeListenerAdapter() {
        @Override
        public void onPageSelected(int position) {
            mTitle.setText(mAdapter.getPageTitle(position));
            mPages.setText(getString(R.string.configure_pages_pattern, position + 1, mAdapter.getCount()));
        }
    };
    viewPager.setOnPageChangeListener(onPageChangeListener);
    viewPager.setAdapter(mAdapter);
    onPageChangeListener.onPageSelected(0);

    return view;
}
 
Example 12
Source File: ViewPagerParallax2.java    From CoordinatorLayoutExample with Apache License 2.0 5 votes vote down vote up
private void setupViewPager(ViewPager viewPager) {
    mFragments = new ArrayList<>();
    for (int i = 0; i < mTitles.length; i++) {
        ListFragment listFragment = ListFragment.newInstance(mTitles[i]);
        mFragments.add(listFragment);
    }
    BaseFragmentAdapter adapter =
            new BaseFragmentAdapter(getSupportFragmentManager(), mFragments, mTitles);


    viewPager.setAdapter(adapter);
}
 
Example 13
Source File: FavouritesFragment.java    From PopCorn with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_favourites, container, false);

    mSmartTabLayout = (SmartTabLayout) view.findViewById(R.id.tab_view_pager_fav);
    mViewPager = (ViewPager) view.findViewById(R.id.view_pager_fav);
    mViewPager.setAdapter(new FavouritesPagerAdapter(getChildFragmentManager(), getContext()));
    mSmartTabLayout.setViewPager(mViewPager);

    return view;
}
 
Example 14
Source File: ChangingActionBarActivity.java    From Painter with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_changing_action_bar);

    ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPager.setAdapter(mAdapter = new ChangingActionBarAdapter());
    viewPager.setOnPageChangeListener(this);

    mActionbarColorSlider = new ActionBarColorSlider(getSupportActionBar(), mAdapter.getColor(0), mAdapter.getColor(1));
}
 
Example 15
Source File: MainActivity.java    From IndicatorSeekBar with Apache License 2.0 5 votes vote down vote up
private void initViews() {
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabLayout);

    viewPager.setAdapter(new PagerAdapter(getSupportFragmentManager()));
    tabLayout.setupWithViewPager(viewPager);

    for (String s : sType) {
        TextView textView = new TextView(this);
        textView.setText(s);
        tabLayout.newTab().setCustomView(textView);
    }

}
 
Example 16
Source File: TabActivity.java    From smartcoins-wallet with MIT License 4 votes vote down vote up
private void setupViewPager(ViewPager viewPager) {
    ViewPagerAdapter adapter = new ViewPagerAdapter(this, getSupportFragmentManager());
    viewPager.setAdapter(adapter);
}
 
Example 17
Source File: SubCategoryActivity.java    From wallpaper with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	currentPageSubLatest = 0;
	currentPageSubRecommended = 0;
	currentPageHottest = 0;
	currentPage = 0;
	isFromRefreshDataSubLatest = true;
	isFromRefreshDataSubRecommended = true;
	isFromRefreshDataHottest = true;
	latestGroups = new ArrayList<Group>();
	recommendedGroups = new ArrayList<Group>();
	hottestGroups = new ArrayList<Group>();
	setContentView(R.layout.activity_subcategory);

	subcategory_title_textview = (TextView) findViewById(R.id.subcategory_title_textview);
	subcategoryBackImage = (ImageView) findViewById(R.id.subcategory_back_image);
	subcategoryBackImage.setOnClickListener(this);

	pager = (ViewPager) findViewById(R.id.pager);
	pager.setOffscreenPageLimit(2);
	fragments = new ArrayList<Fragment>();

	SubLatestFragment sublatestFragment = new SubLatestFragment();
	SubRecommendedFragment subrecommendedFragment = new SubRecommendedFragment();
	HottestFragment hottestfragment = new HottestFragment();
	fragments.add(sublatestFragment);
	fragments.add(subrecommendedFragment);
	fragments.add(hottestfragment);

	latestButton = (RadioButton) findViewById(R.id.radio_sub_latest);
	latestButton.setOnClickListener(this);
	recommendedButton = (RadioButton) findViewById(R.id.radio_sub_recommended);
	recommendedButton.setOnClickListener(this);
	hottestButton = (RadioButton) findViewById(R.id.radio_hottest);
	hottestButton.setOnClickListener(this);

	mAdapter = new ViewPagerAdapter(getSupportFragmentManager(), fragments);
	pager.setAdapter(mAdapter);
	menu = new SlidingMenu(this);
	menu.setMode(SlidingMenu.LEFT);
	menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
	menu.setShadowWidthRes(R.dimen.shadow_width);
	menu.setShadowDrawable(R.drawable.slidingmenu_shadow);
	menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
	menu.setFadeDegree(0.35f);
	menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
	menu.setMenu(R.layout.layout_menu);
	menu.setMode(SlidingMenu.LEFT);
	menu.setMenu(R.layout.layout_menu);
	long screenWidth = WallWrapperEnvConfigure.getScreenWidth();
	menu.setBehindWidth((int) (screenWidth * 0.7));

	pager.setOnPageChangeListener(this);

	menuListView = (ListView) menu.getMenu().findViewById(R.id.menu_listview);
	menuListView.setAdapter(new MenuListViewAdapter(this));
	menuListView.setOnItemClickListener(this);
}
 
Example 18
Source File: SmileyPicker.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
public SmileyPicker(Context paramContext, AttributeSet paramAttributeSet) {
    super(paramContext, paramAttributeSet);
    mContext = paramContext;
    LayoutInflater mInflater = LayoutInflater.from(paramContext);
    View view = mInflater.inflate(R.layout.writeweiboactivity_smileypicker, null);

    ViewPager viewPager = (ViewPager) view.findViewById(R.id.viewpager);
    viewPager.setAdapter(new SmileyPagerAdapter());
    leftPoint = (ImageView) view.findViewById(R.id.left_point);
    centerPoint = (ImageView) view.findViewById(R.id.center_point);
    rightPoint = (ImageView) view.findViewById(R.id.right_point);

    if (true) {
        rightPoint.setVisibility(View.VISIBLE);
    } else {
        rightPoint.setVisibility(View.GONE);
    }
    leftPoint.getDrawable().setLevel(1);
    viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            super.onPageSelected(position);
            switch (position) {
                case 0:
                    leftPoint.getDrawable().setLevel(1);
                    centerPoint.getDrawable().setLevel(0);
                    rightPoint.getDrawable().setLevel(0);
                    break;
                case 1:
                    leftPoint.getDrawable().setLevel(0);
                    centerPoint.getDrawable().setLevel(1);
                    rightPoint.getDrawable().setLevel(0);
                    break;
                case 2:
                    leftPoint.getDrawable().setLevel(0);
                    centerPoint.getDrawable().setLevel(0);
                    rightPoint.getDrawable().setLevel(1);
                    break;

            }
        }
    });
    addView(view);
}
 
Example 19
Source File: IntroActivity.java    From UTubeTV with The Unlicense 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_intro);

  FragmentManager fm = getFragmentManager();
  mTaskFragment = (IntroXMLTaskFragment) fm.findFragmentByTag("task");

  // If the Fragment is non-null, then it is currently being
  // retained across a configuration change.
  if (mTaskFragment == null) {
    mTaskFragment = new IntroXMLTaskFragment();
    fm.beginTransaction().add(mTaskFragment, "task").commit();
  }

  mCloseButton = (Button) findViewById(R.id.close_button);
  mCloseButton.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
      finish();
    }
  });

  mViewPager = (ViewPager) findViewById(R.id.intro_pager);

  introPagerAdapter = new IntroPagerAdapter(this, getSupportFragmentManager());
  introPagerAdapter.setPages(mTaskFragment.getPages());
  mViewPager.setAdapter(introPagerAdapter);

  final LinePageIndicator ind = (LinePageIndicator) findViewById(R.id.line_indicator);
  ind.setViewPager(mViewPager);

  mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
    @Override
    public void onPageSelected(int position) {
      ind.updatePage(position);
      boolean lastPage = position == introPagerAdapter.getCount() - 1;

      mCloseButton.setText((lastPage) ? "Close" : "Read later");
    }
  });

  // show player if activity was destroyed and recreated
  if (savedInstanceState != null) {
    // must wait for the pages to load before we can restore it, so save it here
    mSavedIndex = savedInstanceState.getInt("pager_index");
  }
}
 
Example 20
Source File: MainActivity.java    From android-HorizontalPaging with Apache License 2.0 4 votes vote down vote up
/**
 * Create the activity. Sets up an {@link android.app.ActionBar} with tabs, and then configures the
 * {@link ViewPager} contained inside R.layout.activity_main.
 *
 * <p>A {@link SectionsPagerAdapter} will be instantiated to hold the different pages of
 * fragments that are to be displayed. A
 * {@link android.support.v4.view.ViewPager.SimpleOnPageChangeListener} will also be configured
 * to receive callbacks when the user swipes between pages in the ViewPager.
 *
 * @param savedInstanceState
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Load the UI from res/layout/activity_main.xml
    setContentView(R.layout.sample_main);

    // Set up the action bar. The navigation mode is set to NAVIGATION_MODE_TABS, which will
    // cause the ActionBar to render a set of tabs. Note that these tabs are *not* rendered
    // by the ViewPager; additional logic is lower in this file to synchronize the ViewPager
    // state with the tab state. (See mViewPager.setOnPageChangeListener() and onTabSelected().)
    // BEGIN_INCLUDE (set_navigation_mode)
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    // END_INCLUDE (set_navigation_mode)

    // BEGIN_INCLUDE (setup_view_pager)
    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    // END_INCLUDE (setup_view_pager)

    // 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.
    // BEGIN_INCLUDE (page_change_listener)
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });
    // END_INCLUDE (page_change_listener)

    // BEGIN_INCLUDE (add_tabs)
    // 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));
    }
    // END_INCLUDE (add_tabs)
}