Java tutorial
/*** Copyright (c) 2013 CommonsWare, LLC 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. From _The Busy Coder's Guide to Android Development_ http://commonsware.com/Android */ package com.commonsware.android.preso.slides; import android.content.Context; import android.support.v4.view.PagerAdapter; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; class SlidesAdapter extends PagerAdapter { private static final int[] SLIDES = { R.drawable.img0, R.drawable.img1, R.drawable.img2, R.drawable.img3, R.drawable.img4, R.drawable.img5, R.drawable.img6, R.drawable.img7, R.drawable.img8, R.drawable.img9, R.drawable.img10, R.drawable.img11, R.drawable.img12, R.drawable.img13, R.drawable.img14, R.drawable.img15, R.drawable.img16, R.drawable.img17, R.drawable.img18, R.drawable.img19 }; private static final int[] TITLES = { R.string.title0, R.string.title1, R.string.title2, R.string.title3, R.string.title4, R.string.title5, R.string.title6, R.string.title7, R.string.title8, R.string.title9, R.string.title10, R.string.title11, R.string.title12, R.string.title13, R.string.title14, R.string.title15, R.string.title16, R.string.title17, R.string.title18, R.string.title19 }; private Context ctxt = null; SlidesAdapter(Context ctxt) { this.ctxt = ctxt; } @Override public Object instantiateItem(ViewGroup container, int position) { ImageView page = new ImageView(ctxt); page.setImageResource(getPageResource(position)); container.addView(page, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); return (page); } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); } @Override public int getCount() { return (SLIDES.length); } @Override public boolean isViewFromObject(View view, Object object) { return (view == object); } @Override public String getPageTitle(int position) { return (ctxt.getString(TITLES[position])); } int getPageResource(int position) { return (SLIDES[position]); } }