我试图在onBindViewHolder中设置视图但是无法选择它们
我应该在布局中使用它们的ID或....?
适配器:
public class RV_Adapter extends RecyclerView.Adapter {
private Context context;
private List<Image> images;
public RV_Adapter(Context context, List<Image> Images){
this.context = context;
images = Images;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view= LayoutInflater.from(context).inflate(R.layout.rv_layout,parent,false);
return new ImageViewHolder(view);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
Image image=images.get(position);
holder.
}
@Override
public int getItemCount() {
return images.size();
}
class ImageViewHolder extends RecyclerView.ViewHolder{
private ImageView rvimg;
private TextView rvtxt;
private TextView rvcontent;
public ImageViewHolder(View itemView) {
super(itemView);
rvimg=itemView.findViewById(R.id.rv_imgview);
rvtxt =itemView.findViewById(R.id.rv_title);
rvcontent=itemView.findViewById(R.id.rv_content);
}
}
}
有任何建议如何设置持有人?
答案 0 :(得分:0)
添加:
Graph(int _count, int _spacing, int _chart_width) :
count(_count),
spacing(_spacing),
width((_chart_width - (_count - 1) * _spacing) / _count) {}
再次重新实现抽象方法。
答案 1 :(得分:0)
我正在写一个demoadapterclass。请尝试实施它。如果您遇到任何问题,请告诉我。
public class DemoAdapter extends
RecyclerView.Adapter<DemoAdapter.ViewHolder> {
private List<Image> mImageItemList;
private Context context;
public IRvGalleryImageListener mIRvGalleryImageListener;
public interface IRvGalleryImageListener {
void onClickGalleryImage(Image item, int position);
}
public DemoAdapter(Context context, List<Image> itemList) {
mIRvGalleryImageListener = (IRvGalleryImageListener)context;
this.mImageItemList = itemList;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.galery_image_list_item, null);
return new ViewHolder(layoutView);
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView mTvTitle;
ImageView mIvGalleryImage;
public ViewHolder(View v) {
super(v);
try {
mTvTitle = (TextView) v.findViewById(R.id.tv_title_main);
mIvGalleryImage = (ImageView) v.findViewById(R.id.iv_gallery_image);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mIRvGalleryImageListener.onClickGalleryImage(mImageItemList.get(getAdapterPosition()),getAdapterPosition());
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
if(!TextUtils.isEmpty(mImageItemList.get(position).getTitle()) && !mImageItemList.get(position).getTitle().equals(""))
holder.mTvTitle.setText(mImageItemList.get(position).getTitle());
holder.mIvGalleryImage.setImageURI(Uri.parse(AppConstants.IMAGE_ENDPOINT_CACHED_IMAGE + mImageItemList.get(position).getImage()));
}
@Override
public int getItemCount() {
return this.mImageItemList.size();
}
}