滑动窗口。。

原创 2012年03月27日 20:57:28
package com.geekyouup.paug.awesomepager;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

public class AwesomePagerActivity extends Activity {
    
	private ViewPager awesomePager;

	private Context cxt;
	private AwesomePagerAdapter awesomeAdapter;
	
	private LayoutInflater mInflater;
	private List<View> mListViews;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        cxt = this;
        
        awesomeAdapter = new AwesomePagerAdapter();
        awesomePager = (ViewPager) findViewById(R.id.awesomepager);
        awesomePager.setAdapter(awesomeAdapter);
        
        mListViews = new ArrayList<View>();
        mInflater = getLayoutInflater();
        mListViews.add(mInflater.inflate(R.layout.layout1, null));
        mListViews.add(mInflater.inflate(R.layout.layout2, null));
        mListViews.add(mInflater.inflate(R.layout.layout3, null));
        mListViews.add(mInflater.inflate(R.layout.layout4, null));
        
    }
    
    private class AwesomePagerAdapter extends PagerAdapter{

		
		@Override
		public int getCount() {
			return mListViews.size();
		}

	    /**
	     * Create the page for the given position.  The adapter is responsible
	     * for adding the view to the container given here, although it only
	     * must ensure this is done by the time it returns from
	     * {@link #finishUpdate()}.
	     *
	     * @param container The containing View in which the page will be shown.
	     * @param position The page position to be instantiated.
	     * @return Returns an Object representing the new page.  This does not
	     * need to be a View, but can be some other container of the page.
	     */
		@Override
		public Object instantiateItem(View collection, int position) {

			
			((ViewPager) collection).addView(mListViews.get(position),0);
			
			return mListViews.get(position);
		}

	    /**
	     * Remove a page for the given position.  The adapter is responsible
	     * for removing the view from its container, although it only must ensure
	     * this is done by the time it returns from {@link #finishUpdate()}.
	     *
	     * @param container The containing View from which the page will be removed.
	     * @param position The page position to be removed.
	     * @param object The same object that was returned by
	     * {@link #instantiateItem(View, int)}.
	     */
		@Override
		public void destroyItem(View collection, int position, Object view) {
			((ViewPager) collection).removeView(mListViews.get(position));
		}

		
		
		@Override
		public boolean isViewFromObject(View view, Object object) {
			return view==(object);
		}

		
	    /**
	     * Called when the a change in the shown pages has been completed.  At this
	     * point you must ensure that all of the pages have actually been added or
	     * removed from the container as appropriate.
	     * @param container The containing View which is displaying this adapter's
	     * page views.
	     */
		@Override
		public void finishUpdate(View arg0) {}
		

		@Override
		public void restoreState(Parcelable arg0, ClassLoader arg1) {}

		@Override
		public Parcelable saveState() {
			return null;
		}

		@Override
		public void startUpdate(View arg0) {}
    	
    }
    
    
}


外加一个包  android-support-v4.jar

http://developer.android.com/sdk/compatibility-library.html







相关文章推荐

滑动窗口协议

  • 2014年06月12日 16:09
  • 9.59MB
  • 下载

滑动窗口规模的动态调整算法

  • 2012年06月14日 11:18
  • 1.17MB
  • 下载

TCP-IP详解:滑动窗口(Sliding Window)

从传输数据来讲,TCP/UDP以及其他协议都可以完成数据的传输,从一端传输到另外一端,TCP比较出众的一点就是提供一个可靠的,流控的数据传输,所以实现起来要比其他协议复杂的多,先来看下这两个修饰词的意...

滑动窗口协议模拟.rar

  • 2010年04月21日 19:15
  • 1.12MB
  • 下载

Leetcode 480. Sliding Window Median 滑动窗口中的中位数 解题报告

1 解题思想题目会给一个数组,和一个滑动窗口的大小K,让你找出当这个窗口滑动的过程中,这个K的窗口内的中位数分别是多少?最naive的方式就是在k个窗口内排序就好,这里不解释(因为开销很大啊,(n-k...
  • MebiuW
  • MebiuW
  • 2017年01月13日 15:11
  • 2368

JAVA滑动窗口演示动画

  • 2013年06月05日 08:47
  • 18KB
  • 下载

mfc实现滑动窗口的简单模拟

  • 2012年02月16日 10:14
  • 22.71MB
  • 下载

uva 1606 amphiphilic carbon molecules【把缩写写出来,有惊喜】(滑动窗口)——yhx

Shanghai Hypercomputers, the world's largest computer chip manufacturer, has invented a new classof ...
  • SBS2000
  • SBS2000
  • 2016年05月02日 16:44
  • 112
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:滑动窗口。。
举报原因:
原因补充:

(最多只允许输入30个字)