从 ViewHolder 类在 Glide 中传递上下文?

dav*_*lal 2 android firebase android-glide firebase-storage

我试图在里面传递上下文with(),但“这个”不起作用,也不行getContext()getActivity()。我的课程是一个 ViewHolder,它扩展了RecycleView. 我如何获得上下文?

protected void bind(I item, @Nullable OnContactClickListener<I> listener) {
            Author author = item.getContact().getAuthor();
            Glide.with(this /* context */)
                    .using(new FirebaseImageLoader())
                    .load(storageRef.child("/"+author.getName()+"/pic.jpg"))
                    .error(new IdenticonDrawable(author.getId().getBytes()))
                    .into(avatar);
            String contactName = author.getName();
            name.setText(contactName);
Run Code Online (Sandbox Code Playgroud)

KuL*_*Tel 6

如此简单地获取 avtar 视图的上下文。

protected void bind(I item, @Nullable OnContactClickListener<I> listener) {
            Author author = item.getContact().getAuthor();
            Glide.with(avatar.getContext())
                    .using(new FirebaseImageLoader())
                    .load(storageRef.child("/"+author.getName()+"/pic.jpg"))
                    .error(new IdenticonDrawable(author.getId().getBytes()))
                    .into(avatar);
            String contactName = author.getName();
            name.setText(contactName);
Run Code Online (Sandbox Code Playgroud)