/*
*TODO Adapter
*/
public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private ArrayList<BnBean.DataBean.CatalogBean> list;
private ArrayList<String> imageer;
private Context context;
public MyAdapter(ArrayList<BnBean.DataBean.CatalogBean> list, ArrayList<String> imageer,
Context context) {
this.list = list;
this.imageer = imageer;
this.context = context;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
if (viewType == 0) {
return new ViewHolder1(LayoutInflater.from(context).inflate(R.layout.item_my_bn,
parent, false));
} else {
return new ViewHolder2(LayoutInflater.from(context).inflate(R.layout.item_my_list,
parent, false));
}
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
int i = getItemViewType(position);
if (i == 0) {
ViewHolder1 holder1 = (ViewHolder1) holder;
holder1.bn.setImages(imageer)
.setDelayTime(2000)
.setImageLoader(new ImageLoader() {
@Override
public void displayImage(Context context, Object path, ImageView
imageView) {
String p = (String) path;
Glide.with(context).load(p).into(imageView);
}
}).start();
} else {
if (imageer.size()>0){
position = position - 1;}
ViewHolder2 holder2= (ViewHolder2) holder;
holder2.tv.setText(list.get(position).getName());
Glide.with(context).load(list.get(position).getIcon()).into(holder2.iv);
}
}
@Override
public int getItemCount() {
if (imageer.size() > 0) {
return list.size() + 1;
} else {
return list.size();
}
}
@Override
public int getItemViewType(int position) {
if (imageer.size() > 0 && position == 0) {
return 0;
} else {
return 1;
}
}
public class ViewHolder1 extends RecyclerView.ViewHolder {
@BindView(R.id.bn)
Banner bn;
public ViewHolder1(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}
public class ViewHolder2 extends RecyclerView.ViewHolder {
@BindView(R.id.iv)
ImageView iv;
@BindView(R.id.tv)
TextView tv;
public ViewHolder2(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}
}
banner/recyclerlayout在同adapter中使用
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...