https://github.com/wanglianghai/Encapsulation
http://www.jianshu.com/p/fb24e3343a2e
注意:添加视图要在视图完成后添加,没完成添加的就是没完成的
写adapter不一样的主要的就是数据,视图
创建个接口,接收数据绑定视图
public interface ViewPageHolder<T> {
View createView(ViewGroup viewGroup);
void bind(T data);
}
adapter中用这接口创建视图和绑定视图就行了
public class ViewPageAdapterW<T> extends PagerAdapter
@Override
public Object instantiateItem(ViewGroup container, int position) {
View view = viewPageHolder.createView(container);
viewPageHolder.bind(mData.get(position));
container.addView(view);
return view;
}
用就方便了
class MyHolder implements ViewPageHolder<EntityImage> {
private ImageView mImageView;
@Override
public View createView(ViewGroup viewGroup) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.view_page_item, viewGroup, false);
mImageView = (ImageView) v.findViewById(R.id.image_view);
return v;
}
@Override
public void bind(EntityImage data) {
mImageView.setImageResource(data.imageRes);
}
}