Guest User

test

a guest
Jun 2nd, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.67 KB | None | 0 0
  1. package com.geekyouup.paug.awesomepager;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import android.app.Activity;
  7. import android.content.Context;
  8. import android.graphics.Color;
  9. import android.os.Bundle;
  10. import android.os.Parcelable;
  11. import android.support.v4.view.PagerAdapter;
  12. import android.support.v4.view.ViewPager;
  13. import android.view.LayoutInflater;
  14. import android.view.View;
  15. import android.widget.TextView;
  16.  
  17. public class AwesomePagerActivity extends Activity {
  18.    
  19.     private ViewPager awesomePager;
  20.  
  21.     private Context cxt;
  22.     private AwesomePagerAdapter awesomeAdapter;
  23.    
  24.     private LayoutInflater mInflater;
  25.     private List<View> mListViews;
  26.    
  27.     /** Called when the activity is first created. */
  28.     @Override
  29.     public void onCreate(Bundle savedInstanceState) {
  30.         super.onCreate(savedInstanceState);
  31.         setContentView(R.layout.main);
  32.         cxt = this;
  33.        
  34.         awesomeAdapter = new AwesomePagerAdapter();
  35.         awesomePager = (ViewPager) findViewById(R.id.awesomepager);
  36.         awesomePager.setAdapter(awesomeAdapter);
  37.        
  38.        
  39.         mListViews = new ArrayList<View>();
  40.         mInflater = getLayoutInflater();
  41.         mListViews.add(mInflater.inflate(R.layout.layout1, null));
  42.         mListViews.add(mInflater.inflate(R.layout.layout2, null));
  43.         mListViews.add(mInflater.inflate(R.layout.layout3, null));
  44.        
  45.     }
  46.    
  47.     private class AwesomePagerAdapter extends PagerAdapter{
  48.  
  49.        
  50.         @Override
  51.         public int getCount() {
  52.             return mListViews.size();
  53.         }
  54.  
  55.         /**
  56.          * Create the page for the given position.  The adapter is responsible
  57.          * for adding the view to the container given here, although it only
  58.          * must ensure this is done by the time it returns from
  59.          * {@link #finishUpdate()}.
  60.          *
  61.          * @param container The containing View in which the page will be shown.
  62.          * @param position The page position to be instantiated.
  63.          * @return Returns an Object representing the new page.  This does not
  64.          * need to be a View, but can be some other container of the page.
  65.          */
  66.         @Override
  67.         public Object instantiateItem(View collection, int position) {
  68.  
  69.            
  70.             ((ViewPager) collection).addView(mListViews.get(position),0);
  71.            
  72.             return mListViews.get(position);
  73.         }
  74.  
  75.         /**
  76.          * Remove a page for the given position.  The adapter is responsible
  77.          * for removing the view from its container, although it only must ensure
  78.          * this is done by the time it returns from {@link #finishUpdate()}.
  79.          *
  80.          * @param container The containing View from which the page will be removed.
  81.          * @param position The page position to be removed.
  82.          * @param object The same object that was returned by
  83.          * {@link #instantiateItem(View, int)}.
  84.          */
  85.         @Override
  86.         public void destroyItem(View collection, int position, Object view) {
  87.             ((ViewPager) collection).removeView(mListViews.get(position));
  88.         }
  89.  
  90.        
  91.        
  92.         @Override
  93.         public boolean isViewFromObject(View view, Object object) {
  94.             return view==(object);
  95.         }
  96.  
  97.        
  98.         /**
  99.          * Called when the a change in the shown pages has been completed.  At this
  100.          * point you must ensure that all of the pages have actually been added or
  101.          * removed from the container as appropriate.
  102.          * @param container The containing View which is displaying this adapter's
  103.          * page views.
  104.          */
  105.         @Override
  106.         public void finishUpdate(View arg0) {}
  107.        
  108.  
  109.         @Override
  110.         public void restoreState(Parcelable arg0, ClassLoader arg1) {}
  111.  
  112.         @Override
  113.         public Parcelable saveState() {
  114.             return null;
  115.         }
  116.  
  117.         @Override
  118.         public void startUpdate(View arg0) {}
  119.        
  120.     }
  121.    
  122.    
  123. }
Advertisement
Add Comment
Please, Sign In to add comment