Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Android Lists and Adapters (2015) Lists with RecyclerViews Creating a RecyclerView ViewHolder

What am I doing wrong?

Challenge 1/3: The class below is for a RecyclerView adapter. We need to add a view holder! Create a nested class called GameViewHolder. Make it public and have it extend RecyclerView.ViewHolder. Leave the rest blank for now.

I think I'm following the video, but I'm honestly confused.

Any suggestions?

Thank you.

GameAdapter.java
public class GameAdapter extends RecyclerView.Adapter<GameAdapter.GameViewHolder> {

    private Game[] mGames;

    public GameAdapter(Game[] games) {
        mGames = games;
    }

    @Override
    public GameViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return null;
    }

    @Override
    public void onBindViewHolder(GameViewHolder holder, int position) {
        // code omitted for brevity
    }

    @Override
    public int getItemCount() {
        return 0;
    }

     public class GameViewHolder extends RecyclerView.ViewHolder<GameView.GameViewHolder>{ 
}

4 Answers

Seth Kroger
Seth Kroger
56,413 Points
  1. you're missing a closing curly brace for the holder class. 2. You don't need the diamond operator for RecyclerView.ViewHolder, only RecyclerView.Adapter.

Hi Seth,

I'm sorry. I'm not understanding.

Are you referring to the first line of code?

I'm working on the last line of code. Are your suggestions still applicable?

Thanks!

Seth Kroger
Seth Kroger
56,413 Points

Yes, I'm talking about the last line of code. The inner class should be declared as public class GameViewHolder extends RecyclerView.ViewHolder

Thanks, Seth. I was able to finish the challenge.

public class GameViewHolder extends RecyclerView.ViewHolder{ }