以下是最简单的使用方法,有待完善。
public class MyAdapter extends PagerAdapter {
Context context;
LayoutInflater inflater;
public MyAdapter(Context context) {
this.context = context;
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return 10;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;//官方建议
}
@Override
public Object instantiateItem(final ViewGroup container, final int position) {
View view = inflater.inflate(R.layout.item, null);
container.addView(view);
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
<span style="white-space:pre"> </span>//super.destroyItem(container, position, object); //直接注释掉就可以了
}
}