Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve symbol ViewHolder

I was trying to implement a recycler view. but i am not able to use viewHolder. Please find a solution. Thanks in advance

Screenshot

like image 729
Richu Jain Avatar asked Mar 07 '23 09:03

Richu Jain


1 Answers

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();
            }
        }
like image 131
Dilip Avatar answered Mar 24 '23 15:03

Dilip