我正在使用适配器/ cardLayout / recycleView,我使用this教程进行设置
一切正常,现在我需要下载一张图片(我使用毕加索)并在卡片布局中设置,我需要在每张卡上传递:/
这就是我现在所做的事情:
.bublina.upper {
border-top-right-radius: 300px;
border-top-left-radius: 300px;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
.bublina.lower {
border-top-right-radius: 0;
border-top-left-radius: 0;
border-bottom-right-radius: 300px;
border-bottom-left-radius: 300px;
}
如何将图片传递到正确的卡片?任何提示?
答案 0 :(得分:0)
您需要在Picasso
适配器方法中按onBindViewHolder
加载图片。看看我在适配器中做了什么..
public class OffersAdapter extends RecyclerView.Adapter<OffersAdapter.MyViewHolder> {
private List<OffersModel> list;
Context mContext;
public OffersAdapter(Context mContext, List<OffersModel> list) {
this.list = list;
this.mContext = mContext;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_offers, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
OffersModel offersModel = list.get(position);
holder.product.setText(offersModel.getProduct());
holder.description.setText(offersModel.getDiscription());
Picasso.with(mContext)
.load(offersModel.getImageurl())
.into(holder.offersimage);
}
@Override
public int getItemCount() {
return list.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder{
ImageView offersimage;
TextView product,description,category;
public MyViewHolder(View itemView) {
super(itemView);
offersimage = (ImageView) itemView.findViewById(R.id.offersimage);
product = (TextView) itemView.findViewById(R.id.offertitle);
description = (TextView) itemView.findViewById(R.id.offerdescription);
}
}
}
答案 1 :(得分:0)
删除您的ImageLoad (String Species) { . . }
方法调用以及实施。像这样创建你的适配器类。
public class SimplePlants extends RecyclerView.Adapter<SimplePlants.MyViewHolder> {
private List<Plant> list;
Context mContext;
public SimplePlants(Context mContext, List<Plant> list) {
this.list = list;
this.mContext = mContext;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.your_single_plant_layout, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
Plant plant = list.get(position);
holder.species.setText(plant.getSpecies ());
holder.description.setText(plant.getDiscription());
loadImage (holder.image, plant.getSpecies ());
}
public void loadImage(ImageView imageView, String specie){
String urlFoto = "http://10.0.2.2:3000/images/" + specie + "/Thumbnail.jpg";
Picasso.with(this)
.load(urlFoto)
.into(imageView);
}
@Override
public int getItemCount() {
return list.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder{
ImageView image;
TextView species,description;
public MyViewHolder(View itemView) {
super(itemView);
image = (ImageView) itemView.findViewById(R.id.image);
species = (TextView) itemView.findViewById(R.id.title);
description = (TextView) itemView.findViewById(R.id.description);
}
}
}
我希望这会对你有所帮助。