This is my ImageViewHolder that I have mentioned in my adapter class

public static class ImageTypeViewHolder extends RecyclerView.ViewHolder {
    TextView imageCard_Title,imageCard_Description;
    public ImageView imageCardView;

    public ImageTypeViewHolder(View itemView) {

This is the segment of code written in my onBindViewHolder

((ImageTypeViewHolder) viewHolder).imageCard_Title.setText(modelObject.getImageCardTitle());
((ImageTypeViewHolder) viewHolder).imageCard_Description.setText(modelObject.getImageCardDescription());
((ImageTypeViewHolder) viewHolder).imageCardView.setImageResource(modelObject.getImageCardUrl());

I want to create an option which creates a fullscreen view of the imageview which is a part of the RecyclerView item.

This is the code segment in the activity where i'm adding the imagecard element :

chatList.add(new OustChatModel(1,
            "Sample Image Card",
            "sample description"));

I would like to know what do I do to add a operation that allows the imagecard view to open in a full screen view.

Thanks in advance


In the case of a custom adapter, where you populate your activity/fragment with multiple viewholders, you can make use of an interface to pass data from a fragment to activity.

I provided a interface in the adapter class with a method defined :

public interface onImageClick
{ void onClickImageView(Drawable image);}

Define an object of this interface in this adapter class

onImageClick mObject;

and also declare it in the constructor of the adapter class :

mObject = (onImageClick) this.mCtx;

Now, setup a OnClickListener in the onBindViewHolder()

((ImageTypeViewHolder) viewHolder).imageCardView.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        mObject.onClickImageView(((ImageTypeViewHolder) viewHolder).imageCardView.getDrawable());

Write the interface method declared in the activity/fragment where you access Recycler view items :

public void onClickImageView(Drawable image) {
    //Your operation here
  • 0
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions