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

Picasso library not working in recycler view

So im having this issue in my adapter to were when i go to set the picaso method to convert my immage url it will not allow me to pass the context no matter how i do it. i Have tried this and The calss name .this neither seem to work. Not sure what or why this is happening. Here is the portion of the code i am having problems with.

    public class ContentViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        public TextView mUrl;
        public TextView mTitle;
        public TextView mDate;
        public TextView mAuthor;
        public ImageView mThumbnail;

        public ContentViewHolder(View itemView) {
            super(itemView);
            mUrl= (TextView) itemView.findViewById(R.id.url);
            mTitle = (TextView) itemView.findViewById(R.id.title);
            mDate = (TextView) itemView.findViewById(R.id.date);
            mAuthor = (TextView) itemView.findViewById(R.id.author);
            mThumbnail =(ImageView)itemView.findViewById(R.id.thumbnail);

        }

        public void bindContent(content bloginfo) {
            mUrl.setText(bloginfo.getUrl());
            mTitle.setText(bloginfo.getTitle());
            mDate.setText(bloginfo.getDate());
            mAuthor.setText(bloginfo.getAuthor());

            Picasso.with(MyAdapter.this).load(bloginfo.getThumbnail()).into(mThumbnail);

        }

1 Answer

Hi Alex,

This is somewhat of a more complex issue.

A RecylerView or RecylerView.Adapter does not have Context. You usually get them from Activity or Application classes. The easiest way to pass the context is to pass it through your constructor.

If you need more details of how this is done, can you paste your entire Recycler Adapter file?

That was exactly what i needed now is there a place that explains exactly waht in the world context means because its something that i have not fully under stood yet.

Try this link:

http://stackoverflow.com/questions/3572463/what-is-context-in-android

Context can be a little difficult to understand at first. It will click at some point. I still learn things about it as well.

Thanks that was exactly what i was looking for.