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

android lists and adapters

Next, add one member variable to your new view holder: a public TextView named mTitleLabel.

Bummer! Make sure you are declaring a member variable in the view holder named 'mTitleLabel'.

18af06ad6c363d899f65803230f425e1?s=22&d=https%3a%2f%2fstatic.teamtreehouse.com%2fassets%2fcontent%2fdefault avatar

Challenge Task 2 of 3

Next, add one member variable to your new view holder: a public TextView named mTitleLabel.

Bummer! Make sure you are declaring a member variable in the view holder named 'mTitleLabel'.

GameAdapter.java

1

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

2

3

private Game[] mGames;

4

5

public GameAdapter(Game[] games) {

6

    mGames = games;

7

}

8

9

@Override

10

public GameViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

11

    return null;

12

}

13

14

@Override

15

public void onBindViewHolder(GameViewHolder holder, int position) {

16

    // code omitted for brevity

17

}

18

19

@Override

20

public int getItemCount() {

21

    return 0;

22

}

23

24

/* Add your code here */

25

 public class GameViewHolder extends RecyclerView.ViewHolder {};

26

27

      public TextView mTitleLabel;

28

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;
    }

    /* Add your code here */
     public class GameViewHolder extends RecyclerView.ViewHolder {};

          public TextView mTitleLabel;


}

1 Answer

Hi there,

You've not quite got the embedded class correct.

Your code:

     public class GameViewHolder extends RecyclerView.ViewHolder {};

          public TextView mTitleLabel;

You're closing the class and putting the member variable out side of it. And you don't have a semi-colon after the class braces.

It needs to look like:

  public class GameViewHolder extends RecyclerView.ViewHolder {
    public TextView mTitleLabel;
  }

So, I've moved the closing curly brace down a couple of lines and moved the TextView definition inside the class. And I removed the semi-colon. That should pass that task.

Hope it helps !

Steve.

thnx steve

Hope it worked for you. :-)

yes it worked bt im having trouble completing task 3