虽然我在绑定视图持有者上使用,但由于某些原因,我得到“无法解决方法错误”。如您所见,这是我的第一次尝试,所以我可能犯了一些巨大的错误。我尝试了多种方法,但都没有似乎工作。
package com.techhgeeks.techhgeeks;
import android.support.v7.widget.RecyclerView;
import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;
import android.view.LayoutInflater;
import java.util.List;
import com.bumptech.glide.Glide;
import android.view.View;
import android.view.ViewGroup;
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> implements View.OnClickListener {
private Context context;
private List<MyData> my_data;
public MyAdapter(Context context, List<MyData> my_data) {
this.context = context;
this.my_data = my_data;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_child,parent,false);
return new ViewHolder(itemView);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.description.setText(my_data.get(position).getDescription());
Glide.with(context).load(my_data.get(position).getImage_link()).into(holder.imageView);
}
@Override
public int getItemCount() {
return my_data.size();
}
@Override
public void onClick(View view) {
int position = getAdapterPosition();
}
public class ViewHolder extends RecyclerView.ViewHolder{
public TextView description;
public ImageView imageView;
public ViewHolder(View itemView) {
super(itemView);
description = (TextView) itemView.findViewById(R.id.textView);
imageView = (ImageView) itemView.findViewById(R.id.image);
}
}
}