cn.org.eshow.framwork.adapter.AbViewPagerAdapter.java Source code

Java tutorial

Introduction

Here is the source code for cn.org.eshow.framwork.adapter.AbViewPagerAdapter.java

Source

/*
 * Copyright (C) 2012 www.amsoft.cn
 * 
 * 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 cn.org.eshow.framwork.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * ??ViewPager?
 *
 */
public class AbViewPagerAdapter extends PagerAdapter {

    /** The m context. */
    private Context mContext;

    /** The m list views. */
    private ArrayList<View> mListViews = null;

    /** The m views. */
    private HashMap<Integer, View> mViews = null;

    /**
     * Instantiates a new ab view pager adapter.
     * @param context the context
     * @param mListViews the m list views
     */
    public AbViewPagerAdapter(Context context, ArrayList<View> mListViews) {
        this.mContext = context;
        this.mListViews = mListViews;
        this.mViews = new HashMap<Integer, View>();
    }

    /**
     * ????.
     *
     * @return the count
     * @see android.support.v4.view.PagerAdapter#getCount()
     */
    @Override
    public int getCount() {
        return mListViews.size();
    }

    /**
     * ??Object?View.
     *
     * @param arg0 the arg0
     * @param arg1 the arg1
     * @return true, if is view from object
     * @see android.support.v4.view.PagerAdapter#isViewFromObject(android.view.View, java.lang.Object)
     */
    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == (arg1);
    }

    /**
     * ??View.
     *
     * @param container the container
     * @param position the position
     * @return the object
     * @see android.support.v4.view.PagerAdapter#instantiateItem(android.view.View, int)
     */
    @Override
    public Object instantiateItem(View container, int position) {
        View v = mListViews.get(position);
        ((ViewPager) container).addView(v);
        return v;
    }

    /**
     * ??View.
     *
     * @param container the container
     * @param position the position
     * @param object the object
     * @see android.support.v4.view.PagerAdapter#destroyItem(android.view.View, int, java.lang.Object)
     */
    @Override
    public void destroyItem(View container, int position, Object object) {
        ((ViewPager) container).removeView((View) object);
    }

    /**
     * ??????notifyDataSetChanged.
     *
     * @param object the object
     * @return the item position
     * @see android.support.v4.view.PagerAdapter#getItemPosition(java.lang.Object)
     */
    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }

}