-
-
Notifications
You must be signed in to change notification settings - Fork 440
03.Multiple View Types
zhangpan edited this page Feb 27, 2022
·
5 revisions
public class MultiViewTypesAdapter extends BaseBannerAdapter<BannerData> {
@Override
protected void bindData(BaseViewHolder<BannerData> holder, BannerData data, int position, int pageSize) {
if (getViewType(position) == BannerData.TYPE_NEW) {
holder.setImageResource(R.id.image_view, data.getDrawable());
} else {
ImageView imageView = holder.findViewById(R.id.banner_image);
Glide.with(imageView).load(data.getImagePath()).placeholder(R.drawable.placeholder).into(imageView);
}
}
@Override
public int getLayoutId(int viewType) {
if (viewType == BannerData.TYPE_NEW) {
return R.layout.item_new_type;
}
return R.layout.item_net_image;
}
@Override
public int getViewType(int position) {
return mList.get(position).getType();
}
}
mViewPager
.setLifecycleRegistry(getLifecycle())
.setAdapter(new MultiViewTypesAdapter())
.create(dataList);