標籤:
ViewPager也是一個常用的組件 與ListView類似 當綁定資料後 想重新整理資料 需要在適配器中添加如下方法
protected PagerAdapter galleryAdapter = new PagerAdapter() { @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == ((View)arg1); } @Override public int getCount() { return size; } @Override public Object instantiateItem(View container, int position) { return bindGalleryAdapterItemView(container, position); } @Override public void destroyItem(View container, int position, Object object) { ((ViewPager) container).removeView((View) object); }; @Override public void finishUpdate(View arg0) {} @Override public void restoreState(android.os.Parcelable state, ClassLoader loader) { }; @Override public Parcelable saveState() { return null; } @Override public void startUpdate(View arg0) {} @Override public int getItemPosition(Object object) {
//POSITION_NONE 是一個PagerAdapter的內部常量,值是-2, return POSITION_NONE; } };
以後有空寫個專欄總結一下 http://stackoverflow.com/questions/7263291/viewpager-pageradapter-not-updating-the-view
Android ViewPager更新資料