I was trying to implement a recycler view
. but i am not able to use viewHolder
. Please find a solution. Thanks in advance
You can try this way hope so it will be helpful for you.
public class YourAdapter extends RecyclerView.Adapter<YourAdapter.MyViewHolder> {
private List<String> myList;
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView title, year, genre;
public MyViewHolder(View view) {
super(view);
title = (TextView) view.findViewById(R.id.title);
genre = (TextView) view.findViewById(R.id.genre);
year = (TextView) view.findViewById(R.id.year);
}
}
public YourAdapter(List<String> list) {
this.myList = list;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_row, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
Movie movie = myList.get(position);
holder.title.setText(myList.get(position).getTitle());
}
@Override
public int getItemCount() {
return myList.size();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With