我在android中使用RecyclerView做了一个简单的自定义列表,我已经完成了它,不同的图片在自定义列表中使用,我想让图像单独点击。建议我一些提示。
以下是我自定义列表的图片:
我想让可爱和不喜欢的图片可以点击。
下面可能是recycleView Adpter:
public class recycleReviewAdpter extends RecyclerView.Adapter<recycleReviewAdpter.myViewHolder>{
private Context context;
List<single_row_data> data;
public recycleReviewAdpter(Context context ,List<single_row_data> data) {
this.context=context;
this.data=data;
}
@Override
public myViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view= LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.singel_row, null);
myViewHolder myViewHolder=new myViewHolder(view);
return myViewHolder;
}
@Override
public void onBindViewHolder(myViewHolder holder, int position) {
holder.titelText.setText(data.get(position).getTitel());
holder.shareImage.setImageResource(data.get(position).getSharePic());
holder.likeImage.setImageResource(data.get(position).getLikePic());
holder.disLikeImage.setImageResource(data.get(position).getDisLikePic());
holder.image.setImageResource(data.get(position).getImage());
}
@Override
public int getItemCount() {
return data.size();
}
class myViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
public ImageView likeImage,disLikeImage,shareImage,image;
public TextView titelText;
public myViewHolder(View itemView) {
super(itemView);
likeImage= (ImageView) itemView.findViewById(R.id.likeImage);
disLikeImage= (ImageView) itemView.findViewById(R.id.dislikeImage);
shareImage= (ImageView) itemView.findViewById(R.id.shareImage);
image= (ImageView) itemView.findViewById(R.id.imageView);
titelText= (TextView) itemView.findViewById(R.id.titelText);
}
@Override
public void onClick(View v) {
int id=v.getId();
switch (id){
case R.id.likeImage:
Toast.makeText(v.getContext(),"Like",Toast.LENGTH_LONG).show();
break;
case R.id.dislikeImage:
Toast.makeText(v.getContext(),"Like",Toast.LENGTH_LONG).show();
break;
case R.id.shareImage:
Toast.makeText(v.getContext(),"share",Toast.LENGTH_LONG).show();
break;
default:Toast.makeText(v.getContext(),"Nohting",Toast.LENGTH_LONG).show();
}
}
}
}
答案 0 :(得分:1)
你的代码非常好。 做那件简单的事 对于每个图像视图
public myViewHolder(View itemView) {
super(itemView);
likeImage= (ImageView) itemView.findViewById(R.id.likeImage);
likeImage.setonclickListner(this);
}
答案 1 :(得分:0)
mongos