Java tutorial
/* * Copyright 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package br.com.cardapiodigital; import android.content.Context; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.view.LayoutInflater; import android.view.View; /** * Demonstrates a "screen-slide" animation using a {@link ViewPager}. Because {@link ViewPager} * automatically plays such an animation when calling {@link ViewPager#setCurrentItem(int)}, there * isn't any animation-specific code in this sample. * * <p>This sample shows a "next" button that advances the user to the next step in a wizard, * animating the current screen out (to the left) and the next screen in (from the right). The * reverse animation is played when the user presses the "previous" button.</p> * * @see ScreenSlidePageFragment */ public class ScreenSlideActivity extends FragmentActivity { private static final int NUM_PAGES = 5; private ViewPager mPager; private PagerAdapter mPagerAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_screen_slide); mPager = (ViewPager) findViewById(R.id.pager); mPagerAdapter = new ScreenSlidePagerAdapter(this, R.layout.menu_content); mPager.setAdapter(mPagerAdapter); mPager.setOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageSelected(int page) { } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int arg0) { } }); } private class ScreenSlidePagerAdapter extends PagerAdapter { private Context context; private int resourceID; public ScreenSlidePagerAdapter(Context context, int resourceID) { this.context = context; this.resourceID = resourceID; } @Override public void destroyItem(View view, int arg1, Object object) { ((ViewPager) view).removeView((View) object); } @Override public int getCount() { return NUM_PAGES; } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } @Override public Object instantiateItem(View container, int position) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View row = inflater.inflate(resourceID, null); ((ViewPager) container).addView(row); return row; } } }