send data from recyclerview adapter to activity code example

Example: send data from recyclerview adapter to main activity

public interface OnImageClickListener {
    void onImageClick(String imageData);
}
MainActivity:

public class MainActivity implements OnImageClickListener {
    @Override
    public void onImageClick(String imageData) {
        // handle image data
    }
//...
}
Your VideoAdapter:

    //...
    private OnImageClickListener onImageClickListener;

    public VideoAdapter(ArrayList<Video> data, ArrayList<Video> data2, Activity activity, OnImageClickListener onImageClickListener) {
        this.mData = data;
        this.mData2 = data2;
        this.mACtivity = activity;
        this.onImageClickListener = onImageClickListener;
    }
    //...
    @Override
    public void onBindViewHolder(VideoHolder holder, int position) {
        //...
        holder.restaurantImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onImageClickListener.onImageClick(video2.getPic());
            }
        });
        //...
    }
    //...

Tags:

Java Example