編輯:關於Android編程
這次再對內容為View的ViewPager的適配器PagerAdapter進行簡單的封裝,支持List數據和SparseArray的數據,帶更新視圖功能。
首先,先貼上最上面的抽象類代碼:
/* * Date: 14-8-18 * Project: Access-Control-V2 */ package cn.irains.access_control_v2.common; import android.support.v4.view.PagerAdapter; import android.util.SparseArray; import android.view.View; import android.view.ViewGroup; import java.util.List; /** * 抽象的PagerAdapter實現類,封裝了內容為View的公共操作. * Author: msdx ([email protected]) * Time: 14-8-18 下午2:34 */ public abstract class AbstractViewPagerAdapter extends PagerAdapter { protected SparseArraymViews; public AbstractViewPagerAdapter() { mViews = new SparseArray (); } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } @Override public Object instantiateItem(ViewGroup container, int position) { View view = mViews.get(position); if (view == null) { view = newView(position); mViews.put(position, view); } container.addView(view); return view; } public abstract View newView(int position); public void notifyUpdateView(int position) { View view = updateView(mViews.get(position), position); mViews.put(position, view); notifyDataSetChanged(); } public View updateView(View view, int position) { return view; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView(mViews.get(position)); } }
接下來看數據為List的封裝,代碼如下:
/* * Date: 14-8-18 * Project: Access-Control-V2 */ package cn.irains.access_control_v2.common; import android.view.View; import java.util.List; /** * 抽象的PagerAdapter實現類,封裝了內容為View,數據為List類型的適配器實現. * Author: msdx ([email protected]) * Time: 14-8-18 下午2:34 */ public abstract class AbstractPagerListAdapterextends AbstractViewPagerAdapter { protected List mData; public AbstractPagerListAdapter(List data) { mData = data; } @Override public int getCount() { return mData.size(); } public abstract View newView(int position); public T getItem(int position) { return mData.get(position); } }
同樣,數據為SparseArray的適配器封裝類代碼與其相似,如下:
/* * Date: 14-8-18 * Project: Access-Control-V2 */ package cn.irains.access_control_v2.common; import android.util.SparseArray; import android.view.View; /** * 抽象的PagerAdapter實現類,封裝了內容為View,數據為SparseArray類型的適配器實現. * Author: msdx ([email protected]) * Time: 14-8-18 下午2:34 */ public abstract class AbstractPagerSparseAdapterextends AbstractViewPagerAdapter { protected SparseArray mData; public AbstractPagerSparseAdapter(SparseArray data) { mData = data; } @Override public int getCount() { return mData.size(); } public abstract View newView(int position); public T getItem(int position) { return mData.valueAt(position); } }
android 微信朋友分享,朋友圈分享包名必須寫成 com.weixinWXEntryActivitypackage com.weixin.wxapi;import a
復習一下view滑動的幾種實現方式1.通過layout實現通過不斷重新layout view 達到滑動的效果。 @Override public boolea
在android UI開發中,我們經常會遇到這種需求: 兩個支持滑動的組件,比如listview嵌套多個listview,listview的item是一個viewpage
小米4絕對是小米的一個神機:至少是安卓手機中稍有的可以刷雙系統的,為發燒而生。微軟教程不是人看的!官方就放了句話,然後死都不給教程!坑死人不償命!!!!首先