Answers for "send data from recyclerview adapter to main activity"

0

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());
            }
        });
        //...
    }
    //...
Posted by: Guest on October-26-2020

Code answers related to "send data from recyclerview adapter to main activity"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language